package com.tjtt.tdm.flow.dao.impl;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.hibernate.Query;

import com.tjtt.tdm.base.BaseHibernateDao;
import com.tjtt.tdm.base.PageResult;
import com.tjtt.tdm.exception.DaoException;
import com.tjtt.tdm.exception.ServiceException;
import com.tjtt.tdm.flow.bean.FlowDetailed;
import com.tjtt.tdm.flow.bean.FlowTask;
import com.tjtt.tdm.flow.bean.FlowTaskInfo;
import com.tjtt.tdm.flow.bean.Flowtype;
import com.tjtt.tdm.flow.dao.IWorkflowDao;
/**
 * @author 张海娜
 * 
 */
public class WorkflowDaoImpl extends BaseHibernateDao implements IWorkflowDao {
	public PageResult queryWaitWorkListNew(Map<String, String> filterMap) {
		StringBuffer queryCountString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		queryString.append(" select * from ( ");
		queryString.append(" select t1.id as flowtaskinfoid,t1.flow_task_id as flowtaskid,t2.flow_type_id," +
				"t1.flow_state_id,t2.main_id,t3.renwubh,t3.chanpindh,t3.shiyanlx,t3.fuzher,t3.shiyandd,t3.shiyankssj," +
				"t3.yujijssj,t1.flow_state_name,t2.add_user_name,t2.add_time from flow_task_info t1 " +
				"left join flow_task t2 on t1.flow_task_id=t2.id " +
				"left join kl_junyans t3 on t3.id=t2.main_id "+
				"where  t1.flow_state_id !='finish' and t1.flow_state_id != 'end' and t1.state=0 " );
		if (filterMap != null && !filterMap.isEmpty()) {
			
			queryString.append(" and t1.next_users_id like '%," +filterMap.get("userId") + ",%'  ");
//			if(null != filterMap.get("deptId") &&! "".equals(filterMap.get("deptId"))){
//				queryString.append(" and (t1.next_dept_id= '"+filterMap.get("deptId")+"' or t1.next_dept_id is null)");
//				
//			}
			if(null != filterMap.get("flag")&&!"".equals(filterMap.get("flag"))&&"2".equals(filterMap.get("flag"))){
				queryString.append(" and t1.back_state='1' ");
			}
			if(null != filterMap.get("renwubh")&&!"".equals(filterMap.get("renwubh"))){
				queryString.append(" and t3.renwubh like '%"+filterMap.get("renwubh")+"%'");
			}
			if(null != filterMap.get("chanpindh")&&!"".equals(filterMap.get("chanpindh"))){
				queryString.append(" and t3.chanpindh like '%"+filterMap.get("chanpindh")+"%'");
			}
			if(null != filterMap.get("shiyanlx")&&!"".equals(filterMap.get("shiyanlx"))){
				queryString.append(" and t3.shiyanlx like '%"+filterMap.get("shiyanlx")+"%'");
			}
			if(null != filterMap.get("state")&&!"".equals(filterMap.get("state"))){
				queryString.append(" and t1.flow_state_name like '%"+filterMap.get("state")+"%'");
			}
			if(null != filterMap.get("tianjiar")&&!"".equals(filterMap.get("tianjiar"))){
				queryString.append(" and t2.add_user_name like '%"+filterMap.get("tianjiar")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and t3.shiyankssj >= '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and t3.shiyankssj <= '"+filterMap.get("endtime")+"'");
			}
		}
		
		//========================================================
		queryString.append(") ");
		queryCountString.append("select count(*) from ("+queryString+")");
		String sidx = (String) filterMap.get("sidx");
		String sord = (String) filterMap.get("sord");
		queryString.append(" order by renwubh  " + sord + " ");
		
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	
	
	public PageResult queryDaiqian(Map<String, String> filterMap) {
		StringBuffer queryCountString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		queryString.append(" select * from ( ");
		queryString.append(" select t1.id as flowtaskinfoid,t1.flow_task_id as flowtaskid,t2.flow_type_id," +
				"t1.flow_state_id,t2.main_id,t3.renwubh,t3.chanpindh,t3.shiyanlx,t3.fuzher,t3.shiyandd,t3.shiyankssj," +
				"t3.yujijssj,t1.flow_state_name,t2.add_user_name,t2.add_time from flow_task_info t1 " +
				"left join flow_task t2 on t1.flow_task_id=t2.id " +
				"left join kl_junyans t3 on t3.id=t2.main_id "+
				"where  t1.flow_state_id !='finish' and t1.flow_state_id != 'end' and t1.state=0 " );
		if (filterMap != null && !filterMap.isEmpty()) {
			String rids = filterMap.get("roleId");
			String[] roleIds = rids.split(",");
			queryString.append(" and (");
			for (int i = 0; i < roleIds.length; i++) {
				if(roleIds.length > 1){
					if(i == roleIds.length - 1){
						queryString.append(" t1.next_roles_id like '%," + roleIds[i] + ",%'");
					}else{
						queryString.append(" t1.next_roles_id like '%," + roleIds[i] + ",%' or");
					}
				}else{
					queryString.append(" t1.next_roles_id like '%," + roleIds[i] + ",%'");
				}
			}
			
			queryString.append(" ) and  t1.next_users_id is  null  ");
//			if(null != filterMap.get("deptId") &&! "".equals(filterMap.get("deptId"))){
//				queryString.append(" and (t1.next_dept_id= '"+filterMap.get("deptId")+"' or t1.next_dept_id is null)");
//				
//			}
			if(null != filterMap.get("renwubh")&&!"".equals(filterMap.get("renwubh"))){
				queryString.append(" and t3.renwubh like '%"+filterMap.get("renwubh")+"%'");
			}
			if(null != filterMap.get("chanpindh")&&!"".equals(filterMap.get("chanpindh"))){
				queryString.append(" and t3.chanpindh like '%"+filterMap.get("chanpindh")+"%'");
			}
			if(null != filterMap.get("shiyanlx")&&!"".equals(filterMap.get("shiyanlx"))){
				queryString.append(" and t3.shiyanlx like '%"+filterMap.get("shiyanlx")+"%'");
			}
			if(null != filterMap.get("state")&&!"".equals(filterMap.get("state"))){
				queryString.append(" and t1.flow_state_name like '%"+filterMap.get("state")+"%'");
			}
			if(null != filterMap.get("tianjiar")&&!"".equals(filterMap.get("tianjiar"))){
				queryString.append(" and t2.add_user_name like '%"+filterMap.get("tianjiar")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and t3.shiyankssj => '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and t3.shiyankssj <= '"+filterMap.get("endtime")+"'");
			}
		}
		
		//========================================================
		queryString.append(") ");
		queryCountString.append("select count(*) from ("+queryString+")");
		String sidx = (String) filterMap.get("sidx");
		String sord = (String) filterMap.get("sord");
		queryString.append(" order by shiyankssj " + sord + " ");
		
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	
	//我的请求
	public PageResult queryMyRequestExec(Map<String, String> filterMap){
		StringBuffer queryCountString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		
		//查字段
		queryString.append("select * from (" +
				"select t.id,f.id as taskid,f.flow_name,f.flow_type_id,i.id as taskinfoid,t.renwuname,t.weituodanshibieno,t.lianxiren,t.shenqingdate,t.shuangfangyuedingdate,f.FLOW_STATE_ID " +
				" from GWM_WEITUODAN t left join flow_task f on f.main_id = t.id and f.table_name = 'GWM_WEITUODAN'left join (select t1.id,t1.FLOW_TASK_ID,row_number() over(partition by t1.FLOW_TASK_ID order by t1.id) r from FLOW_TASK_INFO t1 ) i" +
				" on i.FLOW_TASK_ID = f.id and  i.r=1 where f.state != '5' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("userId") && !"".equals(filterMap.get("userId"))){
				queryString.append(" and t.bianzhirenyuan = '"+filterMap.get("userId")+"'" );
			}
			if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname"))){
				queryString.append(" and t.RENWUNAME like '%"+filterMap.get("renwuname")+"%'");
			}
			if(null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))){
				queryString.append(" and t.WEITUODANSHIBIENO like '%"+filterMap.get("shibiehao")+"%'");
			}
			if(null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren"))){
				queryString.append(" and t.LIANXIREN like '%"+filterMap.get("weituoren")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and t.SHENQINGDATE >= '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and t.SHENQINGDATE <= '"+filterMap.get("endtime")+"'");
			}
			if(null != filterMap.get("jdmc")&&!"".equals(filterMap.get("jdmc"))){
				queryString.append(" and t.shuangfangyuedingdate like '%"+filterMap.get("jdmc")+"%'");
			}
			if(null != filterMap.get("rwmc")&&!"".equals(filterMap.get("rwmc"))){
				queryString.append(" and f.FLOW_NAME like '%"+filterMap.get("rwmc")+"%'");
			}
			if(null != filterMap.get("renwustate")&&!"".equals(filterMap.get("renwustate"))){
				if("0".equals(filterMap.get("renwustate"))){
					queryString.append(" and f.FLOW_STATE_ID != 'end'");
				}else{
					queryString.append(" and f.FLOW_STATE_ID = 'end'");
				}
			}
		}
		queryString.append(" union " );
		queryString.append("select t.id,f.id as taskid,f.flow_name,f.flow_type_id,i.id as taskinfoid,t.renwuname,t.weituodanshibieno,t.LIANXIREN,t.shenqingriqi as shenqingdate,t.shuangfangyuedingriqi as shuangfangyuedingdate,f.FLOW_STATE_ID " +
				" from GWM_YANFAJIANCE t left join flow_task f on f.main_id = t.id and f.table_name = 'GWM_YANFAJIANCE' left join (select t1.id,t1.FLOW_TASK_ID,row_number() over(partition by t1.FLOW_TASK_ID order by t1.id) r from FLOW_TASK_INFO t1 ) i" +
				" on i.FLOW_TASK_ID = f.id and  i.r=1 where f.state != '5' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("userId") && !"".equals(filterMap.get("userId"))){
				queryString.append(" and t.bianzhirenyuanid = '"+filterMap.get("userId")+"' "); 
			}
			if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname"))){
				queryString.append(" and t.RENWUNAME like '%"+filterMap.get("renwuname")+"%'");
			}
			if(null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))){
				queryString.append(" and t.weituodanshibieno like '%"+filterMap.get("shibiehao")+"%'");
			}
			if(null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren"))){
				queryString.append(" and t.LIANXIREN like '%"+filterMap.get("weituoren")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and t.SHENQINGRIQI >= '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and t.SHENQINGRIQI <= '"+filterMap.get("endtime")+"'");
			}
			if(null != filterMap.get("jdmc")&&!"".equals(filterMap.get("jdmc"))){
				queryString.append(" and t.shuangfangyuedingriqi like '%"+filterMap.get("jdmc")+"%'");
			}
			if(null != filterMap.get("rwmc")&&!"".equals(filterMap.get("rwmc"))){
				queryString.append(" and f.FLOW_NAME like '%"+filterMap.get("rwmc")+"%'");
			}
			if(null != filterMap.get("renwustate")&&!"".equals(filterMap.get("renwustate"))){
				if("0".equals(filterMap.get("renwustate"))){
					queryString.append(" and f.FLOW_STATE_ID != 'end'");
				}else{
					queryString.append(" and f.FLOW_STATE_ID = 'end'");
				}
			}
		}
		queryString.append(" union ");
		queryString.append("select t.id,f.id as taskid,f.flow_name,f.flow_type_id,i.id as taskinfoid,t.T_TESTNAME as rewuname,t.T_WEITUODANBH as weituodanshibieno,t.T_LIANXIREN as LIANXIREN,t.T_SHENQINGRQ as shenqingdate,t.T_YUEDINGRIQI as shuangfangyuedingdate,f.FLOW_STATE_ID " +
				" from GWM_CHANGGIJIANCE t left join flow_task f on f.main_id = t.id and f.table_name = 'GWM_CHANGGIJIANCE' left join (select t1.id,t1.FLOW_TASK_ID,row_number() over(partition by t1.FLOW_TASK_ID order by t1.id) r from FLOW_TASK_INFO t1 ) i" +
				" on i.FLOW_TASK_ID = f.id and  i.r=1 where f.state != '5' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("userId") && !"".equals(filterMap.get("userId"))){
				queryString.append(" and t.t_weituoren = '"+filterMap.get("userId")+"' ");
			}
			if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname"))){
				queryString.append(" and t.T_TESTNAME like '%"+filterMap.get("renwuname")+"%'");
			}
			if(null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))){
				queryString.append(" and t.T_WEITUODANBH like '%"+filterMap.get("shibiehao")+"%'");
			}
			if(null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren"))){
				queryString.append(" and t.T_LIANXIREN like '%"+filterMap.get("weituoren")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and t.T_SHENQINGRQ >= '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and t.T_SHENQINGRQ <= '"+filterMap.get("endtime")+"'");
			}
			if(null != filterMap.get("jdmc")&&!"".equals(filterMap.get("jdmc"))){
				queryString.append(" and t.T_YUEDINGRIQI like '%"+filterMap.get("jdmc")+"%'");
			}
			if(null != filterMap.get("rwmc")&&!"".equals(filterMap.get("rwmc"))){
				queryString.append(" and f.FLOW_NAME like '%"+filterMap.get("rwmc")+"%'");
			}
			if(null != filterMap.get("renwustate")&&!"".equals(filterMap.get("renwustate"))){
				if("0".equals(filterMap.get("renwustate"))){
					queryString.append(" and f.FLOW_STATE_ID != 'end'");
				}else{
					queryString.append(" and f.FLOW_STATE_ID = 'end'");
				}
			}
		}
		
		queryString.append(" ) ");
		String sidx = (String) filterMap.get("sidx");
		String sord = (String) filterMap.get("sord");
		queryString.append(" order by " + sidx + " " + sord + " ");
		queryCountString.append("select count(*) from ( "+queryString+" )");
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	public PageResult queryReportlist(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append(" SELECT COUNT(*) FROM FLOW_TASK T LEFT JOIN flow_flowtype t1 ON t.flow_type_id = t1.id where 1=1   ");
		queryString.append(" SELECT T.ID," +
						   " T1.FLOWNAME, "+
					       " T.FLOW_NAME,"+
					       " T.FLOW_TYPE_ID,"+
					       " T.FLOW_STATE_ID,"+
					       " T.FLOW_STATE_NAME,"+
					       " T.FLOW_ACTION_TYPE,"+
					       " T.INSTANCE_ID,"+
					       " T.NEXT_ROLES_ID,"+
					       " T.NEXT_ROLES_NAME,"+
					       " T.NEXT_USERS_ID,"+
					       " T.NEXT_USERS_NAME,"+
					       " T.ADD_TIME,"+
					       " T.ADD_USER_ID,"+
					       " T.ADD_USER_NAME,"+
					       " T.URGENT"+
					  	   " FROM FLOW_TASK T LEFT JOIN flow_flowtype t1 ON t.flow_type_id = t1.id where  1=1  ");
		queryString.append(" order by t.add_time desc  ");
		queryCountString.append(" order by t.add_time desc ");
		
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	
	public PageResult queryJianyanlist(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append(" SELECT COUNT(*) FROM FLOW_TASK T LEFT JOIN flow_flowtype t1 ON t.flow_type_id = t1.id where 1=1   ");
		queryString.append(" SELECT T.ID," +
						   " T1.FLOWNAME, "+
					       " T.FLOW_NAME,"+
					       " T.FLOW_TYPE_ID,"+
					       " T.FLOW_STATE_ID,"+
					       " T.FLOW_STATE_NAME,"+
					       " T.FLOW_ACTION_TYPE,"+
					       " T.INSTANCE_ID,"+
					       " T.NEXT_ROLES_ID,"+
					       " T.NEXT_ROLES_NAME,"+
					       " T.NEXT_USERS_ID,"+
					       " T.NEXT_USERS_NAME,"+
					       " T.ADD_TIME,"+
					       " T.ADD_USER_ID,"+
					       " T.ADD_USER_NAME,"+
					       " T.URGENT"+
					  	   " FROM FLOW_TASK T LEFT JOIN flow_flowtype t1 ON t.flow_type_id = t1.id where  1=1  ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("flowtype") &&! "".equals(filterMap.get("flowtype"))){
							queryString.append(" and t1.FLOWNAME like '%").append(filterMap.get("flowtype")).append("%' ");
							queryCountString.append(" and t1.FLOWNAME like '%").append(filterMap.get("flowtype")).append("%' ");
			}
			if(null != filterMap.get("flowname") &&! "".equals(filterMap.get("flowname"))){
				queryString.append(" and t.FLOW_NAME like '%").append(filterMap.get("flowname")).append("%' ");
				queryCountString.append(" and t.FLOW_NAME like '%").append(filterMap.get("flowname")).append("%' ");
			}
			queryString.append(" and  t.flow_state_id !='baofei' and exists(select * from jianyan t2 where t.id=t2.taskid) ");
			queryCountString.append(" and  t.flow_state_id !='baofei' and exists(select * from jianyan t2 where t.id=t2.taskid) ");
			queryString.append(" order by T.Urgent desc,t.add_time desc  ");
			queryCountString.append(" order by T.Urgent desc,t.add_time desc ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	
	public PageResult queryJianyandetaillist(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append(" SELECT COUNT(*) FROM jianyan t1 LEFT JOIN flow_task t2 ON t1.taskid = t2.id where 1=1   ");
		queryString.append(" select T1.ID,T2.FLOW_NAME,T1.STATENAME,T1.ISCHECK,T1.REMARK,T1.CREATEPERSON,T1.CREATETIME,T1.STATEID FROM jianyan t1 LEFT JOIN flow_task t2 ON t1.taskid = t2.id where 1=1   ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("taskid") &&! "".equals(filterMap.get("taskid"))){
				queryString.append(" and t1.taskid = '").append(filterMap.get("taskid")).append("' ");
				queryCountString.append(" and t1.taskid = '").append(filterMap.get("taskid")).append("' ");
			}
			queryString.append(" order by T1.ID  ");
			queryCountString.append(" order by T1.ID ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	
	public PageResult queryWaitWorkListNewMyTask(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		//查询具体字段
		queryString.append("select n.* from (");
		queryString.append("select f.id,ft.id as flowtaskinfoid,ff.flowname,f.flow_name,f.flow_state_name,f.flow_type_id,c.T_WEITUODANBH,c.T_LIANXIREN," +
				"c.T_SHENQINGRQ,c.T_TESTNAME from FLOW_TASK f left join FLOW_TASK_INFO ft on ft.flow_task_id = f.id left join FLOW_FLOWTYPE ff on f.flow_type_id = ff.id" +
				" left join GWM_CHANGGIJIANCE c on f.main_id = c.id and f.table_name = 'GWM_CHANGGIJIANCE' where f.flow_state_id = 'end' and f.flow_type_id = '2121' and f.STATE <> 1 ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("userId") &&! "".equals(filterMap.get("userId"))){
				queryString.append(" and f.add_user_id="+filterMap.get("userId"));
			}
			if(null != filterMap.get("flowtype") &&! "".equals(filterMap.get("flowtype"))){
				queryString.append(" and ff.FLOWNAME like '%").append(filterMap.get("flowtype") ).append("%' ");
			}
			if(null != filterMap.get("flowname") &&! "".equals(filterMap.get("flowname"))){
				queryString.append(" and f.FLOW_NAME like '%").append(filterMap.get("flowname") ).append("%' ");
			}
			if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname"))){
				queryString.append(" and c.T_TESTNAME like '%"+filterMap.get("renwuname")+"%'");
			}
			if(null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))){
				queryString.append(" and c.T_WEITUODANBH like '%"+filterMap.get("shibiehao")+"%'");
			}
			if(null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren"))){
				queryString.append(" and c.T_LIANXIREN like '%"+filterMap.get("weituoren")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and c.T_SHENQINGRQ > '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and c.T_SHENQINGRQ < '"+filterMap.get("endtime")+"'");
			}
		}
		queryString.append(" union ");
		queryString.append("select f.id,ft.id as flowtaskinfoid,ff.flowname,f.flow_name,f.flow_state_name,f.flow_type_id,y.weituodanshibieno,y.LIANXIREN," +
				"y.SHENQINGRIQI,y.RENWUNAME  from FLOW_TASK f  left join FLOW_TASK_INFO ft on ft.flow_task_id = f.id left join FLOW_FLOWTYPE ff on f.flow_type_id = ff.id " +
				" left join GWM_YANFAJIANCE y on f.main_id = y.id and f.table_name = 'GWM_YANFAJIANCE' where f.flow_state_id = 'end' and f.flow_type_id = '2241' and f.STATE <> 1 ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("userId") &&! "".equals(filterMap.get("userId"))){
				queryString.append(" and f.add_user_id="+filterMap.get("userId"));
			}
			if(null != filterMap.get("flowtype") &&! "".equals(filterMap.get("flowtype"))){
				queryString.append(" and ff.FLOWNAME like '%").append(filterMap.get("flowtype") ).append("%' ");
			}
			if(null != filterMap.get("flowname") &&! "".equals(filterMap.get("flowname"))){
				queryString.append(" and f.FLOW_NAME like '%").append(filterMap.get("flowname") ).append("%' ");
			}
			if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname"))){
				queryString.append(" and y.RENWUNAME like '%"+filterMap.get("renwuname")+"%'");
			}
			if(null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))){
				queryString.append(" and y.weituodanshibieno like '%"+filterMap.get("shibiehao")+"%'");
			}
			if(null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren"))){
				queryString.append(" and y.LIANXIREN like '%"+filterMap.get("weituoren")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and y.SHENQINGRIQI > '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and y.SHENQINGRIQI < '"+filterMap.get("endtime")+"'");
			}
		}
		queryString.append(" union ");
		queryString.append("select f.id,ft.id as flowtaskinfoid,ff.flowname,f.flow_name,f.flow_state_name,f.flow_type_id,w.WEITUODANSHIBIENO,w.LIANXIREN," +
				"w.SHENQINGDATE,w.RENWUNAME from FLOW_TASK f left join FLOW_TASK_INFO ft on ft.flow_task_id = f.id left join FLOW_FLOWTYPE ff on f.flow_type_id = ff.id" +
				"  left join GWM_WEITUODAN w  on f.main_id = w.id and f.table_name = 'GWM_WEITUODAN' where f.flow_state_id = 'end' and f.flow_type_id = '2181'  and f.STATE <> 1 ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("userId") &&! "".equals(filterMap.get("userId"))){
				queryString.append(" and f.add_user_id="+filterMap.get("userId"));
			}
			if(null != filterMap.get("flowtype") &&! "".equals(filterMap.get("flowtype"))){
				queryString.append(" and ff.FLOWNAME like '%").append(filterMap.get("flowtype") ).append("%' ");
			}
			if(null != filterMap.get("flowname") &&! "".equals(filterMap.get("flowname"))){
				queryString.append(" and f.FLOW_NAME like '%").append(filterMap.get("flowname") ).append("%' ");
			}
			if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname"))){
				queryString.append(" and w.RENWUNAME like '%"+filterMap.get("renwuname")+"%'");
			}
			if(null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))){
				queryString.append(" and w.WEITUODANSHIBIENO like '%"+filterMap.get("shibiehao")+"%'");
			}
			if(null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren"))){
				queryString.append(" and w.LIANXIREN like '%"+filterMap.get("weituoren")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and w.SHENQINGDATE > '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and w.SHENQINGDATE < '"+filterMap.get("endtime")+"'");
			}
		}
		if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname")) || null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))
				|| null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren")) || null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))
				|| null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
		}else{
			queryString.append(" union ");
			queryString.append("select f.id,ft.id as flowtaskinfoid,ff.flowname,f.flow_name,f.flow_state_name,f.flow_type_id,'','','',''  from FLOW_TASK f" +
					" left join FLOW_TASK_INFO ft  on ft.flow_task_id = f.id left join FLOW_FLOWTYPE ff on f.flow_type_id = ff.id left join GWM_WEITUODAN w" +
					" on f.main_id = w.id and f.table_name = 'GWM_WEITUODAN' where f.flow_state_id = 'end' and f.flow_type_id != '2241' and f.flow_type_id != '2121'" +
					" and f.flow_type_id != '2181' and f.STATE <> 1 ");
			if (filterMap != null && !filterMap.isEmpty()) {
				if(null != filterMap.get("userId") &&! "".equals(filterMap.get("userId"))){
					queryString.append(" and f.add_user_id="+filterMap.get("userId"));
				}
				if(null != filterMap.get("flowtype") &&! "".equals(filterMap.get("flowtype"))){
					queryString.append(" and ff.FLOWNAME like '%").append(filterMap.get("flowtype") ).append("%' ");
				}
				if(null != filterMap.get("flowname") &&! "".equals(filterMap.get("flowname"))){
					queryString.append(" and f.FLOW_NAME like '%").append(filterMap.get("flowname") ).append("%' ");
				}
			}
		}
		queryString.append(") n ");
		String sidx = (String) filterMap.get("sidx");
		String sord = (String) filterMap.get("sord");
		queryString.append(" order by " + sidx + " " + sord + " ");
		queryCountString.append(" SELECT COUNT(*) FROM ( "+queryString+" )");
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}

	public PageResult queryXieZuoWaitWorkListNew(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append(" SELECT COUNT(*) FROM FLOW_TASK T LEFT JOIN flow_flowtype t1 ON t.flow_type_id = t1.id where  t.flow_state_id != 'end' and t.flow_state_id !='finish' " +
					  	   " and t.flow_type_id = '443' and t.flow_state_id = 'txysjld' ");
		queryString.append(" SELECT T.ID," +
						   " T1.FLOWNAME, "+
					       " T.FLOW_NAME,"+
					       " T.FLOW_TYPE_ID,"+
					       " T.FLOW_STATE_ID,"+
					       " T.FLOW_STATE_NAME,"+
					       " T.FLOW_ACTION_TYPE,"+
					       " T.INSTANCE_ID,"+
					       " T.NEXT_ROLES_ID,"+
					       " T.NEXT_ROLES_NAME,"+
					       " T.NEXT_USERS_ID,"+
					       " T.NEXT_USERS_NAME,"+
					       " T.ADD_TIME,"+
					       " T.ADD_USER_ID,"+
					       " T.ADD_USER_NAME,t.shiyanbh "+
					  	   " FROM FLOW_TASK T LEFT JOIN flow_flowtype t1 ON t.flow_type_id = t1.id where  t.flow_state_id != 'end' and t.flow_state_id !='finish' " +
					  	   " and t.flow_type_id = '443' and t.flow_state_id = 'txysjld' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("state") &&! "".equals(filterMap.get("state"))){
				queryString.append(" and t.state="+filterMap.get("state"));
				queryCountString.append(" and t.state="+filterMap.get("state"));
			}
			if(null != filterMap.get("userId") &&! "".equals(filterMap.get("userId"))){
				queryString.append(" and (t.next_users_id LIKE '%,"+filterMap.get("userId")+",%' ");
				queryCountString.append(" and (t.next_users_id LIKE '%,"+filterMap.get("userId")+",%' ");
			}
			String rids = filterMap.get("roleId");
			String[] roleIds = rids.split(",");
			for(String roleId : roleIds){
				queryString.append(" or t.next_roles_id like '%," + roleId + ",%'");
				queryCountString.append(" or t.next_roles_id like '%," + roleId + ",%'");
			}
			queryString.append(" )");
			queryCountString.append(" )");
			if(null != filterMap.get("deptId") &&! "".equals(filterMap.get("deptId"))){
				queryString.append(" and (t.next_dept_id="+filterMap.get("deptId")+" or t.next_dept_id is null)");
				queryCountString.append(" and (t.next_dept_id="+filterMap.get("deptId")+" or t.next_dept_id is null)");
			}
			if(null != filterMap.get("flowtype") &&! "".equals(filterMap.get("flowtype"))){
				queryString.append(" and t1.FLOWNAME like '%").append(filterMap.get("flowtype") ).append("%' ");
				queryCountString.append(" and t1.FLOWNAME like '%").append(filterMap.get("flowtype") ).append("%' ");
			}
			if(null != filterMap.get("flowname") &&! "".equals(filterMap.get("flowname"))){
				queryString.append(" and t.FLOW_NAME like '%").append(filterMap.get("flowname") ).append("%' ");
				queryCountString.append(" and t.FLOW_NAME like '%").append(filterMap.get("flowname") ).append("%' ");
			}

			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append(" order by T." + sidx + " " + sord + " ");
			queryCountString.append(" order by T." + sidx + " " + sord + " ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	

	public PageResult queryDaiQianWaitWorkListNew(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append(" SELECT COUNT(*) FROM ( SELECT distinct T.ID," +
				   " T1.FLOWNAME, "+
			       " T.FLOW_NAME,"+
			       " T.FLOW_TYPE_ID,"+
			       " T.FLOW_STATE_ID,"+
			       " T.FLOW_STATE_NAME,"+
			       " T.FLOW_ACTION_TYPE,"+
			       " T.NEXT_ROLES_ID,"+
			       " T.NEXT_ROLES_NAME,"+
			       " T.NEXT_USERS_ID,"+
			       " T.NEXT_USERS_NAME,"+
			       " T.ADD_TIME,"+
			       " T.ADD_USER_ID,"+
			       " T.ADD_USER_NAME,"+
			       " t2.id flowtaskinfoid "+
			  	   " FROM FLOW_TASK T LEFT JOIN flow_flowtype t1 ON t.flow_type_id = t1.id " +
			  	   " left join flow_task_info t2 on t.id=t2.flow_task_id " +
			  	   " where  t.flow_state_id != 'end' and t.flow_state_id !='finish'  ");
		queryString.append(" SELECT distinct T.ID," +
						   " T1.FLOWNAME, "+
					       " T.FLOW_NAME,"+
					       " T.FLOW_TYPE_ID,"+
					       " T2.FLOW_STATE_ID,"+
					       " T2.FLOW_STATE_NAME,"+
					       " T.FLOW_ACTION_TYPE,"+
					       " T2.NEXT_ROLES_ID,"+
					       " T2.NEXT_ROLES_NAME,"+
					       " T2.NEXT_USERS_ID,"+
					       " T2.NEXT_USERS_NAME,"+
					       " T.ADD_TIME,"+
					       " T.ADD_USER_ID,"+
					       " T.ADD_USER_NAME,"+
					       " t2.id flowtaskinfoid  "+
					  	   " FROM FLOW_TASK T LEFT JOIN flow_flowtype t1 ON t.flow_type_id = t1.id  " +
					  	   " left join flow_task_info t2 on t.id=t2.flow_task_id " +
					  	   " where  t2.flow_state_id != 'end' and t2.flow_state_id !='finish' ");
    	if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("state") &&! "".equals(filterMap.get("state"))){
				queryString.append(" and t2.state="+filterMap.get("state"));
				queryCountString.append(" and t2.state="+filterMap.get("state"));
			}
			String rids = filterMap.get("roleId");
			String[] roleIds = rids.split(",");
			queryString.append(" and (");
			queryCountString.append(" and (");
			for (int i = 0; i < roleIds.length; i++) {
				if(roleIds.length > 1){
					if(i == roleIds.length - 1){
						queryString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%'");
						queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%'");
					}else{
						queryString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%' or");
						queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%' or");
					}
				}else{
					queryString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%'");
					queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%'");
				}
			}
			
			queryString.append(" or (t2.next_users_id like '%," +filterMap.get("userId") + ",%' and t.next_roles_id is not null ) )");
			queryCountString.append(" or (t2.next_users_id like '%," + filterMap.get("userId") + ",%' and t.next_roles_id is not null) )");
			if(null != filterMap.get("deptId") &&! "".equals(filterMap.get("deptId"))){
				queryString.append(" and (t2.next_dept_id= '"+filterMap.get("deptId")+"' or t.next_dept_id is null)");
				queryCountString.append(" and (t2.next_dept_id= '"+filterMap.get("deptId")+"' or t.next_dept_id is null)");
				
			}
			if(null != filterMap.get("flowtype") &&! "".equals(filterMap.get("flowtype"))){
				queryString.append(" and t1.FLOWNAME like '%").append(filterMap.get("flowtype") ).append("%' ");
				queryCountString.append(" and t1.FLOWNAME like '%").append(filterMap.get("flowtype") ).append("%' ");
			}
			if(null != filterMap.get("flowname") &&! "".equals(filterMap.get("flowname"))){
				queryString.append(" and t.FLOW_NAME like '%").append(filterMap.get("flowname") ).append("%' ");
				queryCountString.append(" and t.FLOW_NAME like '%").append(filterMap.get("flowname") ).append("%' ");
			}
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append(" order by t.add_time desc  ");
			queryCountString.append(" order by t.add_time desc) ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	public void updateQianShou(String ids,String userId,String userName) {
		String[] idss = ids.split(",");
		for(String id : idss){
			FlowTaskInfo flowTaskinfo = (FlowTaskInfo)this.getHibernateTemplate().get(FlowTaskInfo.class,Long.parseLong(id));
			flowTaskinfo.setNextUsersId(","+userId+",");
			flowTaskinfo.setNextUsersName(","+userName+",");
			flowTaskinfo.setNextRolesId("");
			flowTaskinfo.setNextRolesName("");
			this.getHibernateTemplate().update(flowTaskinfo);
		}
	}
/***
 * 试验进度管理
 * 
 */
	public PageResult queryWaitExpWorkListNew(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		String filterValue = new String();
		
		//查询具体字段
		queryString.append("select n.* from (");
		queryString.append("select t.id,ft.id as flowtaskinfoid,ff.flowname,t.flow_name,t.flow_state_id,t.flow_state_name,t.flow_type_id,c.T_WEITUODANBH as T_WEITUODANBH,c.T_LIANXIREN as WEITUOREN," +
				"c.T_SHENQINGRQ as WEITUOTIME,c.T_TESTNAME as RENWUNAME,t.ADD_USER_NAME,t.ADD_TIME from FLOW_TASK t left join FLOW_TASK_INFO ft on ft.flow_task_id = t.id left join FLOW_FLOWTYPE ff on t.flow_type_id = ff.id" +
				" left join GWM_CHANGGIJIANCE c on t.main_id = c.id and t.table_name = 'GWM_CHANGGIJIANCE' where t.flow_type_id = '2121' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			String type = filterMap.get("type");
			if("0".equals(type)){//待发起的试验
				queryString.append(" and t.state='1' ");
			}else if("1".equals(type)){//已完成的试验
				queryString.append("  and t.flow_state_id = 'end' ");
			}else if("2".equals(type)){//正在进行的试验
				queryString.append("  and t.flow_state_id != 'end' and t.flow_state_id !='finish' and t.state='0'");
			}else if("3".equals(type)){//已终止的试验
				queryString.append("  and t.state='3' ");
			}else if("5".equals(type)){//已挂起的试验
				queryString.append("  and t.state='2' ");
			}else{}

			filterValue = filterMap.get("flowtype");
			if(filterValue != null && !filterValue.isEmpty()){
				queryString.append(" and t1.FLOWNAME like '%").append(filterValue).append("%' ");
			}
			filterValue = filterMap.get("flowname");
			if(filterValue != null && !filterValue.isEmpty()){
				queryString.append(" and t.FLOW_NAME like '%").append(filterValue).append("%' ");
			}
			filterValue = filterMap.get("flowstatename");
			if(filterValue != null && !filterValue.isEmpty()){
				queryString.append(" and t.FLOW_STATE_NAME like '%").append(filterValue).append("%' ");
			}
			if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname"))){
				queryString.append(" and c.T_TESTNAME like '%"+filterMap.get("renwuname")+"%'");
			}
			if(null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))){
				queryString.append(" and c.T_WEITUODANBH like '%"+filterMap.get("shibiehao")+"%'");
			}
			if(null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren"))){
				queryString.append(" and c.T_LIANXIREN like '%"+filterMap.get("weituoren")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and c.T_SHENQINGRQ > '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and c.T_SHENQINGRQ < '"+filterMap.get("endtime")+"'");
			}
		}
		queryString.append(" union ");
		queryString.append("select t.id,ft.id as flowtaskinfoid,ff.flowname,t.flow_name,t.flow_state_id,t.flow_state_name,t.flow_type_id,y.weituodanshibieno as T_WEITUODANBH,y.LIANXIREN as WEITUOREN," +
				"y.SHENQINGRIQI as WEITUOTIME,y.RENWUNAME as RENWUNAME,t.ADD_USER_NAME,t.ADD_TIME from FLOW_TASK t left join FLOW_TASK_INFO ft on ft.flow_task_id = t.id left join FLOW_FLOWTYPE ff on t.flow_type_id = ff.id " +
				" left join GWM_YANFAJIANCE y on t.main_id = y.id and t.table_name = 'GWM_YANFAJIANCE' where t.flow_type_id = '2241' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			String type = filterMap.get("type");
			if("0".equals(type)){//待发起的试验
				queryString.append(" and t.state='1' ");
			}else if("1".equals(type)){//已完成的试验
				queryString.append("  and t.flow_state_id = 'end' ");
			}else if("2".equals(type)){//正在进行的试验
				queryString.append("  and t.flow_state_id != 'end' and t.flow_state_id !='finish' and t.state='0'");
			}else if("3".equals(type)){//已终止的试验
				queryString.append("  and t.state='3' ");
			}else if("5".equals(type)){//已挂起的试验
				queryString.append("  and t.state='2' ");
			}else{}

			filterValue = filterMap.get("flowtype");
			if(filterValue != null && !filterValue.isEmpty()){
				queryString.append(" and t1.FLOWNAME like '%").append(filterValue).append("%' ");
			}
			filterValue = filterMap.get("flowname");
			if(filterValue != null && !filterValue.isEmpty()){
				queryString.append(" and t.FLOW_NAME like '%").append(filterValue).append("%' ");
			}
			filterValue = filterMap.get("flowstatename");
			if(filterValue != null && !filterValue.isEmpty()){
				queryString.append(" and t.FLOW_STATE_NAME like '%").append(filterValue).append("%' ");
			}
			if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname"))){
				queryString.append(" and y.RENWUNAME like '%"+filterMap.get("renwuname")+"%'");
			}
			if(null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))){
				queryString.append(" and y.weituodanshibieno like '%"+filterMap.get("shibiehao")+"%'");
			}
			if(null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren"))){
				queryString.append(" and y.LIANXIREN like '%"+filterMap.get("weituoren")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and y.SHENQINGRIQI > '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and y.SHENQINGRIQI < '"+filterMap.get("endtime")+"'");
			}
		}
		queryString.append(" union ");
		queryString.append("select t.id,ft.id as flowtaskinfoid,ff.flowname,t.flow_name,t.flow_state_id,t.flow_state_name,t.flow_type_id,w.WEITUODANSHIBIENO as T_WEITUODANBH,w.LIANXIREN as WEITUOREN," +
				"w.SHENQINGDATE as WEITUOTIME,w.RENWUNAME as RENWUNAME,t.ADD_USER_NAME,t.ADD_TIME from FLOW_TASK t left join FLOW_TASK_INFO ft on ft.flow_task_id = t.id left join FLOW_FLOWTYPE ff on t.flow_type_id = ff.id" +
				" left join GWM_WEITUODAN w on t.main_id = w.id and t.table_name = 'GWM_WEITUODAN' where t.flow_type_id = '2181' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			String type = filterMap.get("type");
			if("0".equals(type)){//待发起的试验
				queryString.append(" and t.state='1' ");
			}else if("1".equals(type)){//已完成的试验
				queryString.append("  and t.flow_state_id = 'end' ");
			}else if("2".equals(type)){//正在进行的试验
				queryString.append("  and t.flow_state_id != 'end' and t.flow_state_id !='finish' and t.state='0'");
			}else if("3".equals(type)){//已终止的试验
				queryString.append("  and t.state='3' ");
			}else if("5".equals(type)){//已挂起的试验
				queryString.append("  and t.state='2' ");
			}else{}

			filterValue = filterMap.get("flowtype");
			if(filterValue != null && !filterValue.isEmpty()){
				queryString.append(" and t1.FLOWNAME like '%").append(filterValue).append("%' ");
			}
			filterValue = filterMap.get("flowname");
			if(filterValue != null && !filterValue.isEmpty()){
				queryString.append(" and t.FLOW_NAME like '%").append(filterValue).append("%' ");
			}
			filterValue = filterMap.get("flowstatename");
			if(filterValue != null && !filterValue.isEmpty()){
				queryString.append(" and t.FLOW_STATE_NAME like '%").append(filterValue).append("%' ");
			}
			if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname"))){
				queryString.append(" and w.RENWUNAME like '%"+filterMap.get("renwuname")+"%'");
			}
			if(null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))){
				queryString.append(" and w.WEITUODANSHIBIENO like '%"+filterMap.get("shibiehao")+"%'");
			}
			if(null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren"))){
				queryString.append(" and w.LIANXIREN like '%"+filterMap.get("weituoren")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and w.SHENQINGDATE > '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and w.SHENQINGDATE < '"+filterMap.get("endtime")+"'");
			}
		}
		if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname")) || null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))
				|| null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren")) || null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))
				|| null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
		}else{
			queryString.append(" union ");
			queryString.append("select t.id, ft.id as flowtaskinfoid,ff.flowname,t.flow_name,t.flow_state_id,t.flow_state_name,t.flow_type_id,'' as T_WEITUODANBH,'' as WEITUOREN,'' as WEITUOTIME,'' as RENWUNAME,t.ADD_USER_NAME,t.ADD_TIME from FLOW_TASK t" +
					" left join FLOW_TASK_INFO ft on ft.flow_task_id = t.id left join FLOW_FLOWTYPE ff on t.flow_type_id = ff.id left join GWM_WEITUODAN w" +
					" on t.main_id = w.id and t.table_name = 'GWM_WEITUODAN' where t.flow_type_id != '2241' and t.flow_type_id != '2121'" +
					" and t.flow_type_id != '2181' ");
			if (filterMap != null && !filterMap.isEmpty()) {
				String type = filterMap.get("type");
				if("0".equals(type)){//待发起的试验
					queryString.append(" and t.state='1' ");
				}else if("1".equals(type)){//已完成的试验
					queryString.append("  and t.flow_state_id = 'end' ");
				}else if("2".equals(type)){//正在进行的试验
					queryString.append("  and t.flow_state_id != 'end' and t.flow_state_id !='finish' and t.state='0'");
				}else if("3".equals(type)){//已终止的试验
					queryString.append("  and t.state='3' ");
				}else if("5".equals(type)){//已挂起的试验
					queryString.append("  and t.state='2' ");
				}else{}
	
				filterValue = filterMap.get("flowtype");
				if(filterValue != null && !filterValue.isEmpty()){
					queryString.append(" and t1.FLOWNAME like '%").append(filterValue).append("%' ");
				}
				filterValue = filterMap.get("flowname");
				if(filterValue != null && !filterValue.isEmpty()){
					queryString.append(" and t.FLOW_NAME like '%").append(filterValue).append("%' ");
				}
				filterValue = filterMap.get("flowstatename");
				if(filterValue != null && !filterValue.isEmpty()){
					queryString.append(" and t.FLOW_STATE_NAME like '%").append(filterValue).append("%' ");
				}
				filterValue = filterMap.get("starttime");
				if(filterValue != null && !filterValue.isEmpty()){
					queryString.append(" and to_char(t.ADD_TIME,'yyyy-mm-dd') >='").append(filterValue).append("'");
				}
				filterValue = filterMap.get("endtime");
				if(filterValue != null && !filterValue.isEmpty()){
					queryString.append(" and to_char(t.ADD_TIME,'yyyy-mm-dd') <='").append(filterValue).append("'");
				}
			}
		}
		queryString.append(" ) n ");
		String sidx = (String) filterMap.get("sidx");
		String sord = (String) filterMap.get("sord");
		queryString.append(" order by " + sidx + " " + sord + " ");
		queryCountString.append(" SELECT COUNT(*)  from ( " +queryString+ ")");
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	
	/**
	 * 我的代办试验显示到jqrid
	 * @return
	 * @throws IOException
	 * @throws ServiceException String
	 * @author 张海娜
	 * @date 2013-2-22 下午03:53:34
	 */
	public PageResult queryWaitWorkList(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append("select count(*) from (select v.faultid as regulationid,"+
				 " f.flowname as flowname, "+
			       " s.username as username, "+
			       " to_char(v.weavetime,'yyyy-MM-dd ') as weavetime, "+
			       " v.flowtype_id as flowtype_id, "+
			       " v.state as state, "+
			       " v.stateid as stateid "+
					 " from tdm_faulthandling v "+
					 " left join sys_users s "+
					 "   on s.userid = v.userid "+
					 " left join flow_flowtype f "+
					 "   on f.id = v.flowtype_id "+
					 "   where v.stateid != 'end' "+
					 " union "+
					 " select t.regulationid, "+
					 "      f.flowname, "+
					 "      s.username, "+
					 " to_char(t.weavetime,'yyyy-MM-dd '),"+
					 "      t.flowtype_id, "+
					 "      t.state, "+
					 "      t.stateid "+
					 " from tdm_codereview t "+
					 " left join sys_users s "+
					 "   on s.userid = t.userid "+
					 " left join flow_flowtype f "+
					 "   on f.id = t.flowtype_id "+
					 "  where t.stateid != 'end' " +
					 " union "+
					 " select t.detail_id as regulationid," +
					 "f.flowname as flowname," +
					 "s.username as username, " +
					 "to_char(t.operatortime,'yyyy-MM-dd ') as weavetime," +
					 "t.flowtype as flowtype_id," +
					 " t.state as state, " +
					 "t.statenum as stateid " +
					 "from tdm_testcenter_detail t  " +
					 "left join sys_users s on s.userid = t.operatorperson	 " +
					 "left join flow_flowtype f  on f.id = t.flowtype " +
					 " where t.statenum != 'end' and t.step='0')");
		queryString.append("  select v.faultid as regulationid, "+
					       " f.flowname as flowname, "+
					       " s.username as username, "+
					       " to_char(v.weavetime,'yyyy-MM-dd ') as weavetime, "+
					       " v.flowtype_id as flowtype_id, "+
					       " v.state as state, "+
					       " v.stateid as stateid "+
							 " from tdm_faulthandling v "+
							 " left join sys_users s "+
							 "   on s.userid = v.userid "+
							 " left join flow_flowtype f "+
							 "   on f.id = v.flowtype_id "+
							 "   where v.stateid != 'end' "+
							 " union "+
							 " select t.regulationid, "+
							 "      f.flowname, "+
							 "      s.username, "+
							 " to_char(t.weavetime,'yyyy-MM-dd '),"+
							 "      t.flowtype_id, "+
							 "      t.state, "+
							 "      t.stateid "+
							 " from tdm_codereview t "+
							 " left join sys_users s "+
							 "   on s.userid = t.userid "+
							 " left join flow_flowtype f "+
							 "   on f.id = t.flowtype_id "+
							 "  where t.stateid != 'end' "+
							 " union "+
							 " select t.detail_id as regulationid," +
							 "f.flowname as flowname," +
							 "s.username as username, " +
							 "to_char(t.operatortime,'yyyy-MM-dd ') as weavetime," +
							 "t.flowtype as flowtype_id," +
							 " t.state as state, " +
							 "t.statenum as stateid " +
							 "from tdm_testcenter_detail t  " +
							 "left join sys_users s on s.userid = t.operatorperson	 " +
							 "left join flow_flowtype f  on f.id = t.flowtype " +
							 " where t.statenum != 'end' and t.step='0'");
		if (filterMap != null && !filterMap.isEmpty()) {
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append(" order by " + sidx + " " + sord + " ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	
	public List getFlowStates(long id)
	{
		String strSql = "select statusafter from flow_detailed where instanceid="+id;
		Query query = getSession().createSQLQuery(strSql);
		return query.list();
	}
	
	public List getFlowDetailList(long id)
	{
		String strSql = "select * from flow_detailed where flow_task_id="+id+" order by id asc";
		Query query = getSession().createSQLQuery(strSql);
		return query.list();
		
	}
	
	public String getJianyanstate(String id,String state)
	{
		String strSql = "select stateid from jianyan where taskid="+id+" and ischeck='"+state+"' ";
		Query query = getSession().createSQLQuery(strSql);
		String states = "";
		List lists = query.list();
		for(int i=0;i<lists.size();i++){
			if (i==0){
				states = lists.get(i).toString();
			}
			else{
				states+=","+lists.get(i).toString();
			}
		}
		return states;
	}
	public List getTestCenterFlowDetailList(long id,long instanceid)
	{
		String strSql = "select * from flow_detailed where flow_type_id="+id+" and instanceid = "+instanceid+" order by id asc";
		Query query = getSession().createSQLQuery(strSql);
		return query.list();
	}
	public String getFlowfilepath(String id) {
		String strSql = "select filename from flow_flowtype where id="+id;
		Query query = getSession().createSQLQuery(strSql);
		List list = query.list();
		if (list.size()>0)
		{
			return list.get(0).toString();
		}
		return "";
	}

	/**
	 * 我的已办试验显示到jqrid
	 * @return
	 * @throws IOException
	 * @throws ServiceException String
	 * @author 张海娜
	 * @date 2013-2-22 下午03:53:34
	 */
	public PageResult queryDoneWorkList(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		//查询具体字段
		queryString.append("select flowtaskinfoid,flowname,flow_name,flow_state_name,FLOW_STATE_ID,flowstatename," +
				"flowtaskid,weituodanbh,lianxiren,shenqingdate,renwuname from (");
		queryString.append("select distinct f.id as flowtaskinfoid,ff.flowname,ft.flow_name,ft.flow_state_name," +
				"f.FLOW_STATE_ID,f.FLOW_STATE_NAME as flowstatename,f.id flowtaskid,c.T_WEITUODANBH as weituodanbh," +
				"c.T_LIANXIREN as lianxiren,c.T_SHENQINGRQ as shenqingdate,c.T_TESTNAME as renwuname from FLOW_DETAILED t left join FLOW_TASK_INFO f on t.flow_task_id = f.flow_task_id" +
				" left join FLOW_FLOWTYPE ff on t.flow_type_id = ff.id left join flow_task ft on t.FLOW_TASK_ID = ft.id left join GWM_CHANGGIJIANCE c" +
				" on ft.main_id = c.id and ft.table_name = 'GWM_CHANGGIJIANCE' where 1 = 1 and t.flow_type_id = '2121' and ft.STATE <> 1 and ft.flow_state_id != 'end' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("userId") &&! "".equals(filterMap.get("userId"))){
				queryString.append(" and t.operatorperson_id = "+filterMap.get("userId"));
			}
			if(null != filterMap.get("flowtype") &&! "".equals(filterMap.get("flowtype"))){
				queryString.append(" and ff.FLOWNAME like '%").append(filterMap.get("flowtype") ).append("%' ");
			}
			if(null != filterMap.get("flowname") &&! "".equals(filterMap.get("flowname"))){
				queryString.append(" and f.FLOW_NAME like '%").append(filterMap.get("flowname") ).append("%' ");
			}
			if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname"))){
				queryString.append(" and c.T_TESTNAME like '%"+filterMap.get("renwuname")+"%'");
			}
			if(null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))){
				queryString.append(" and c.T_WEITUODANBH like '%"+filterMap.get("shibiehao")+"%'");
			}
			if(null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren"))){
				queryString.append(" and c.T_LIANXIREN like '%"+filterMap.get("weituoren")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and c.T_SHENQINGRQ > '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and c.T_SHENQINGRQ < '"+filterMap.get("endtime")+"'");
			}
		}
		queryString.append(" union ");
		queryString.append("select distinct f.id as flowtaskinfoid,ff.flowname,ft.flow_name,ft.flow_state_name," +
				"f.FLOW_STATE_ID,f.FLOW_STATE_NAME as flowstatename,f.id flowtaskid,y.weituodanshibieno as weituodanbh," +
				"y.LIANXIREN as lianxiren,y.SHENQINGRIQI as shenqingdate,y.RENWUNAME as renwuname from FLOW_DETAILED t left join FLOW_TASK_INFO f on t.flow_task_id = f.flow_task_id " +
				" left join FLOW_FLOWTYPE ff on t.flow_type_id = ff.id left join flow_task ft on t.FLOW_TASK_ID = ft.id left join GWM_YANFAJIANCE y " +
				" on ft.main_id = y.id and ft.table_name = 'GWM_YANFAJIANCE' where 1 = 1 and t.flow_type_id = '2241' and ft.STATE <> 1 and ft.flow_state_id != 'end' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("userId") &&! "".equals(filterMap.get("userId"))){
				queryString.append(" and t.operatorperson_id = "+filterMap.get("userId"));
			}
			if(null != filterMap.get("flowtype") &&! "".equals(filterMap.get("flowtype"))){
				queryString.append(" and ff.FLOWNAME like '%").append(filterMap.get("flowtype") ).append("%' ");
			}
			if(null != filterMap.get("flowname") &&! "".equals(filterMap.get("flowname"))){
				queryString.append(" and f.FLOW_NAME like '%").append(filterMap.get("flowname") ).append("%' ");
			}
			if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname"))){
				queryString.append(" and y.RENWUNAME like '%"+filterMap.get("renwuname")+"%'");
			}
			if(null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))){
				queryString.append(" and y.weituodanshibieno like '%"+filterMap.get("shibiehao")+"%'");
			}
			if(null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren"))){
				queryString.append(" and y.LIANXIREN like '%"+filterMap.get("weituoren")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and y.SHENQINGRIQI > '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and y.SHENQINGRIQI < '"+filterMap.get("endtime")+"'");
			}
		}
		queryString.append(" union ");
		queryString.append("select distinct f.id as flowtaskinfoid,ff.flowname,ft.flow_name,ft.flow_state_name," +
				"f.FLOW_STATE_ID,f.FLOW_STATE_NAME as flowstatename,f.id flowtaskid,w.WEITUODANSHIBIENO as weituodanbh," +
				"w.LIANXIREN as lianxiren,w.SHENQINGDATE as shenqingdate,w.RENWUNAME as renwuname from FLOW_DETAILED t left join FLOW_TASK_INFO f on t.flow_task_id = f.flow_task_id " +
				" left join FLOW_FLOWTYPE ff on t.flow_type_id = ff.id left join flow_task ft on t.FLOW_TASK_ID = ft.id left join GWM_WEITUODAN w on ft.main_id = w.id " +
				" and ft.table_name = 'GWM_WEITUODAN' where 1 = 1 and t.flow_type_id = '2181' and ft.STATE <> 1 and ft.flow_state_id != 'end' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("userId") &&! "".equals(filterMap.get("userId"))){
				queryString.append(" and t.operatorperson_id = "+filterMap.get("userId"));
			}
			if(null != filterMap.get("flowtype") &&! "".equals(filterMap.get("flowtype"))){
				queryString.append(" and ff.FLOWNAME like '%").append(filterMap.get("flowtype") ).append("%' ");
			}
			if(null != filterMap.get("flowname") &&! "".equals(filterMap.get("flowname"))){
				queryString.append(" and f.FLOW_NAME like '%").append(filterMap.get("flowname") ).append("%' ");
			}
			if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname"))){
				queryString.append(" and w.RENWUNAME like '%"+filterMap.get("renwuname")+"%'");
			}
			if(null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))){
				queryString.append(" and w.WEITUODANSHIBIENO like '%"+filterMap.get("shibiehao")+"%'");
			}
			if(null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren"))){
				queryString.append(" and w.LIANXIREN like '%"+filterMap.get("weituoren")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and w.SHENQINGDATE > '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and w.SHENQINGDATE < '"+filterMap.get("endtime")+"'");
			}
		}
		//报告修改流程--------开始----------
		queryString.append(" union ");
		queryString.append("select distinct f.id as flowtaskinfoid,ff.flowname,ft.flow_name,ft.flow_state_name," +
				"f.FLOW_STATE_ID,f.FLOW_STATE_NAME as flowstatename,f.id flowtaskid,w.RE_WEITUODANHAO as weituodanbh," +
				"w.RE_WEITUOREN as lianxiren,w.re_shenqingtime as shenqingdate,ft.flow_name as renwuname from FLOW_DETAILED t left join FLOW_TASK_INFO f on t.flow_task_id = f.flow_task_id " +
				" left join FLOW_FLOWTYPE ff on t.flow_type_id = ff.id left join flow_task ft on t.FLOW_TASK_ID = ft.id left join GWM_REPORT_UPDATE w on ft.main_id = w.re_id " +
				" and ft.table_name = 'GWM_REPORT_UPDATE' where 1 = 1 and t.flow_type_id = '2481' and ft.STATE <> 1 and ft.flow_state_id != 'end' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("userId") &&! "".equals(filterMap.get("userId"))){
				queryString.append(" and t.operatorperson_id = "+filterMap.get("userId"));
			}
			if(null != filterMap.get("flowtype") &&! "".equals(filterMap.get("flowtype"))){
				queryString.append(" and ff.FLOWNAME like '%").append(filterMap.get("flowtype") ).append("%' ");
			}
			if(null != filterMap.get("flowname") &&! "".equals(filterMap.get("flowname"))){
				queryString.append(" and f.FLOW_NAME like '%").append(filterMap.get("flowname") ).append("%' ");
			}
			if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname"))){
				queryString.append(" and w.RENWUNAME like '%"+filterMap.get("renwuname")+"%'");
			}
			if(null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))){
				queryString.append(" and w.RE_WEITUODANHAO like '%"+filterMap.get("shibiehao")+"%'");
			}
			if(null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren"))){
				queryString.append(" and w.RE_WEITUOREN like '%"+filterMap.get("weituoren")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and w.re_shenqingtime > '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and w.re_shenqingtime < '"+filterMap.get("endtime")+"'");
			}
		}
		//报告修改流程----结束--------
		if(null != filterMap.get("renwuname")&&!"".equals(filterMap.get("renwuname")) || null != filterMap.get("shibiehao")&&!"".equals(filterMap.get("shibiehao"))
				|| null != filterMap.get("weituoren")&&!"".equals(filterMap.get("weituoren")) || null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))
				|| null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
		}else{
			queryString.append(" union ");
			queryString.append("select distinct f.id as flowtaskinfoid,ff.flowname,ft.flow_name,ft.flow_state_name," +
					" f.FLOW_STATE_ID,f.FLOW_STATE_NAME as flowstatename,f.id flowtaskid,'','','',''" +
					"  from FLOW_DETAILED t  left join FLOW_TASK_INFO f on t.flow_task_id = f.flow_task_id left join FLOW_FLOWTYPE ff on t.flow_type_id = ff.id " +
					"  left join flow_task ft on t.FLOW_TASK_ID = ft.id " +
					" where 1 = 1 and t.flow_type_id != '2241' and t.flow_type_id != '2121' and t.flow_type_id != '2181' and t.flow_type_id != '2481'  and ft.STATE <> 1 and ft.flow_state_id != 'end' ");
			if (filterMap != null && !filterMap.isEmpty()) {
				if(null != filterMap.get("userId") &&! "".equals(filterMap.get("userId"))){
					queryString.append(" and t.operatorperson_id = "+filterMap.get("userId"));
				}
				if(null != filterMap.get("flowtype") &&! "".equals(filterMap.get("flowtype"))){
					queryString.append(" and ff.FLOWNAME like '%").append(filterMap.get("flowtype") ).append("%' ");
				}
				if(null != filterMap.get("flowname") &&! "".equals(filterMap.get("flowname"))){
					queryString.append(" and f.FLOW_NAME like '%").append(filterMap.get("flowname") ).append("%' ");
				}
			}
		}
		queryString.append(") n ");
		String sidx = (String) filterMap.get("sidx");
		String sord = (String) filterMap.get("sord");
		queryString.append(" order by " + sidx + " " + sord + " ");
		queryCountString.append(" SELECT COUNT(*)  from ( " +queryString+ ")");
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}

	/**
	 * 查看全部流程操作详细
	 * @return
	 * @throws IOException
	 * @throws ServiceException String
	 * @author 张海娜
	 * @date 2013-3-12 下午02:23:26
	 */
	public PageResult queryWorkDetailList(String id,Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		queryString.append("select  t.id ,t.operatorperson,t.operatortime,t.statusbefore,t.statusafter,t.remark from flow_detailed t  where t.instanceid = "+id+"  ");
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from (select  t.id ,t.operatorperson,t.operatortime,t.statusbefore,t.statusafter,t.remark from flow_detailed t  where t.instanceid = "+id+" ) ");
		if (filterMap != null && !filterMap.isEmpty()) {
			String sidx = (String)filterMap.get("sidx");
			String sord = (String)filterMap.get("sord");
			queryString.append(" order by " + sidx + " " + sord );
		}
		
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);	
	}

	/**
	 * 查看某一个流程的操作详细
	 * @return
	 * @throws IOException
	 * @throws ServiceException String
	 * @author 张海娜
	 * @date 2013-3-12 下午02:23:26
	 */
	public PageResult queryWorkDetailList2(String stateid, String id,
			Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		queryString.append("select  t.id ,t.operatorperson,t.operatortime,t.statusbefore,t.statusafter,t.remark from flow_detailed t  where t.instanceid = "+id+" and t.statusbeforeid = '"+stateid+"' ");
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from (select  t.id ,t.operatorperson,t.operatortime,t.statusbefore,t.statusafter,t.remark from flow_detailed t  where t.instanceid = "+id+"  and t.statusbeforeid = '"+stateid+"' ) ");
		if (filterMap != null && !filterMap.isEmpty()) {
			String sidx = (String)filterMap.get("sidx");
			String sord = (String)filterMap.get("sord");
			queryString.append(" order by " + sidx + " " + sord );
		}
		
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);	
	}

	/**
	 * 我的理化中心代办试验显示到jqrid
	 * @return
	 * @throws IOException
	 * @throws ServiceException String
	 * @author 张海娜
	 * @date 2013-2-22 下午03:53:34
	 */
	public PageResult queryRationalizeWaitWorkList(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append("select count(*) from (" +
						   "  select l.id as regulationid, "+
						   "    f.flowname as flowname,"+
						   "    s.username as username,"+
						   "    to_char(l.request_date, 'yyyy-MM-dd ') as weavetime,"+
						   "    l.flowtypeid as flowtype_id,"+
						   "    l.state as state,"+
						   "    l.stateid as stateid,"+
						   "    l.flowtype as flowtype"+
						   "  from lh_test l"+
						   "  left join sys_users s"+
							"  on s.userid = l.request_user_id"+
							"  left join flow_flowtype f"+
							"  on f.id = l.flowtypeid"+
							" where l.stateid != 'end'"+
							"  and l.flowtype != '0' or l.flowtype !='2' "+
				           " ) ");
		queryString.append("  select l.id as regulationid, "+
						   "    f.flowname as flowname,"+
						   "    s.username as username,"+
						   "    to_char(l.request_date, 'yyyy-MM-dd ') as weavetime,"+
						   "    l.flowtypeid as flowtype_id,"+
						   "    l.state as state,"+
						   "    l.stateid as stateid,"+
						   "    l.flowtype as flowtype"+
						   "  from lh_test l"+
						   "  left join sys_users s"+
							"  on s.userid = l.request_user_id"+
							"  left join flow_flowtype f"+
							"  on f.id = l.flowtypeid"+
							" where l.stateid != 'end'"+
							"  and l.flowtype != '0' or l.flowtype !='2' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append(" order by " + sidx + " " + sord + " ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
 
 
	/**
	 * 我的计量中心代办显示到jqrid
	 * @return
	 * @throws IOException
	 * @throws ServiceException String
	 * @author zxm
	 * @date 2013-4-15 下午20:10:34
	 */
	public PageResult queryWaitWorkListJL(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append("select count(*) from (" +
						   "  select l.id as jlFirstid, "+
						   "    f.flowname as flowname,"+
						   "    s.username as username,"+
						   "    to_char(l.CREATE_TIME, 'yyyy-MM-dd ') as weavetime,"+
						   "    l.flowtype as flowtype,"+
						   "    l.state as state,"+
						   "    l.stateid as stateid,"+
						   "    l.flowState as flowState"+
						   "  from JL_FIRST l"+
						   "  left join sys_users s"+
							"  on s.userid = l.CREATE_USER_ID"+
							"  left join flow_flowtype f"+
							"  on f.id = l.flowtype"+
							" where l.stateid != 'end'"+
							"  and l.flowState != '0' and l.flowState !='2' "+
				           " ) ");
		queryString.append("  select l.id as jlFirstid, "+
						   "    f.flowname as flowname,"+
						   "    s.username as username,"+
						   "    to_char(l.CREATE_TIME, 'yyyy-MM-dd ') as weavetime,"+
						   "    l.flowtype as flowtype,"+
						   "    l.state as state,"+
						   "    l.stateid as stateid,"+
						   "    l.flowState as flowState"+
						   "  from JL_FIRST l"+
						   "  left join sys_users s"+
							"  on s.userid = l.CREATE_USER_ID"+
							"  left join flow_flowtype f"+
							"  on f.id = l.flowtype"+
							" where l.stateid != 'end'"+
							"  and l.flowState != '0' and l.flowState !='2' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append(" order by " + sidx + " " + sord + " ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	/**
	 * 周检
	 */
	public PageResult queryWaitWorkListJLTest(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append("select count(*) from (" +
						   "  select l.id as jlFirstid, "+
						   "    f.flowname as flowname,"+
						   "    s.username as username,"+
						   "    to_char(l.CREATE_TIME, 'yyyy-MM-dd ') as weavetime,"+
						   "    l.flowtypeid as flowtypeid,"+
						   "    l.state as state,"+
						   "    l.stateid as stateid,"+
						   "    l.flowType as flowType"+
						   "  from JL_TEST l"+
						   "  left join sys_users s"+
							"  on s.userid = l.CREATE_USER_ID"+
							"  left join flow_flowtype f"+
							"  on f.id = l.flowtype"+
							" where l.stateid != 'end'"+
							"  and l.flowType != '0' and l.flowType !='2' "+
				           " ) ");
		queryString.append("  select l.id as jlFirstid, "+
						   "    f.flowname as flowname,"+
						   "    s.username as username,"+
						   "    to_char(l.CREATE_TIME, 'yyyy-MM-dd ') as weavetime,"+
						   "    l.flowtypeid as flowtypeid,"+
						   "    l.state as state,"+
						   "    l.stateid as stateid,"+
						   "    l.flowtype as flowtype"+
						   "  from JL_TEST l"+
						   "  left join sys_users s"+
							"  on s.userid = l.CREATE_USER_ID"+
							"  left join flow_flowtype f"+
							"  on f.id = l.flowtype"+
							" where l.stateid != 'end'"+
							"  and l.flowType != '0' and l.flowType !='2' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append(" order by " + sidx + " " + sord + " ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	
	public int getUndoWorkCount(Map<String, String> filterMap) {
		// TODO Auto-generated method stub
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append(" SELECT COUNT(*) FROM flow_task t where 1=1 and t.flow_state_id != 'end' and t.flow_state_id !='finish' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("state") &&! "".equals(filterMap.get("state"))){
				queryCountString.append(" and t.state="+filterMap.get("state"));
			}
			if(null != filterMap.get("userId") &&! "".equals(filterMap.get("userId"))){
				queryCountString.append(" and (t.next_users_id LIKE '%,"+filterMap.get("userId")+",%'");
			}
			String rids = filterMap.get("roleId");
			String[] roleIds = rids.split(",");
			for(String roleId : roleIds){
				queryCountString.append(" or t.next_roles_id like '%," + roleId + ",%'");
			}
			if(null != filterMap.get("deptId") &&! "".equals(filterMap.get("deptId"))){
				queryCountString.append(" and (t.next_dept_id="+filterMap.get("deptId")+" or t.next_dept_id is null)");
			}
			queryCountString.append(")");
		}
		Query query = this.getSession().createSQLQuery(queryCountString.toString());
		List<Number> count = query.list();
		int total = Integer.parseInt(count.get(0).toString());
//		System.out.println(total);
		return total;
	}
 

	public PageResult queryWaitWorkDetailList(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append("select count(*) from flow_detailed t left join flow_task t1 on t.flow_task_id = t1.id where 1=1 ");
		queryString.append("select t.id, t2.renwubh,t.statusbefore,t.statusafter,t.operatorperson,to_char(t.operatortime,'yyyy-MM-dd HH24:Mi:ss')," +
				"t.statusbeforeid,t.statusafterid,t.flow_task_id,t1.flow_type_id,t1.flow_action_type,t.actiontype,t.actiondescript,t.remark,t1.main_id from flow_detailed t " +
				"left join flow_task t1 on t.flow_task_id = t1.id " +
				"left join kl_junyans t2 on t1.main_id=t2.id where 1=1  ");
		if (filterMap != null && !filterMap.isEmpty()) {
			String filterValue = new String();
			filterValue = filterMap.get("flowTaskId");
			if(filterValue != null && !filterValue.isEmpty()){
				queryString.append(" and t.flow_task_id = '").append(filterValue).append("' ");
				queryCountString.append(" and t.flow_task_id = '").append(filterValue).append("' ");
			}
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			//queryString.append(" order by " + sidx + " " + sord + "  ");
			queryString.append("  order by t.operatortime desc  ");
			
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
   /**
    * 
    *方法描述：查看试验中心流程的操作详细记录
    *@author: wangxd
    *@date： 2013-5-28 下午06:57:21
    *@param filterMap
    *@return
    */
	public PageResult queryTestCenterWaitWorkDetailList(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append("select count(*) from flow_detailed t left join flow_task t1 on t.flow_task_id = t1.id where 1=1 ");
		queryString.append("select t.id, t1.flow_name,t.statusbefore,t.statusafter,t.operatorperson,to_char(t.operatortime,'yyyy-MM-dd HH24:Mi:ss')," +
				"t.statusbeforeid,t.statusafterid,t.flow_task_id,t1.flow_type_id,t1.instance_id,t1.flow_action_type from flow_detailed t " +
				"left join flow_task t1 on t.flow_task_id = t1.id where 1=1 ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("testFlowId") &&! "".equals(filterMap.get("testFlowId"))){
				queryString.append("and  t.instanceid = '" + filterMap.get("testFlowId") + "' ");
				queryCountString.append("and t.instanceid = '" + filterMap.get("testFlowId") + "' ");
			}
			if(null != filterMap.get("flowtypeId") &&! "".equals(filterMap.get("flowtypeId"))){
				queryString.append("and  t.flow_type_id = '" + filterMap.get("flowtypeId") + "' ");
				queryCountString.append("and t.flow_type_id = '" + filterMap.get("flowtypeId") + "' ");
			}
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append(" order by " + sidx + " " + sord + " ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	/**
	 * 
	 *方法描述：根据操作人的操作记录查询流程的当前状态
	 *@author: wangxd
	 *@date： 2013-6-7 上午09:34:26
	 *@param instanceId
	 *@param flowTypeId
	 *@param flowStateId
	 *@param flowStateId1
	 *@return
	 */
	  public List<FlowTask> queryTaskByIdName(Long instanceId,Long flowTypeId) 
	  {
		  List<FlowTask> list = null;
		  String hql = "from FlowTask t where  t.instanceId =?  and t.flowTypeId =? and t.flowStateId !='finish')";
		   
		  list = super.getHibernateTemplate().find(hql, new Object[]{instanceId,flowTypeId});
		  
		  return list;
	  }
	
	
	public FlowTask getFlowTaskById(String id) {
		// TODO Auto-generated method stub
		return (FlowTask)getHibernateTemplate().get(FlowTask.class, new Long(id));
	}
	
	public void updateFlowTask(FlowTask flowTask) {
		// TODO Auto-generated method stub
		getHibernateTemplate().update(flowTask);
	}
	
	public List<FlowTask> getFlowTaskByFlowTypeIdAndInstanceId(Long flowTypeId,
			Long instanceId) {
		// TODO Auto-generated method stub
		List<FlowTask> list = null;
		String hql = "from FlowTask t where  t.instanceId =?  and t.flowTypeId =? )";
		   
		list = super.getHibernateTemplate().find(hql, new Object[]{instanceId,flowTypeId});
		  
		return list;
	}
	
	public void saveFlowDetailed(FlowDetailed flowDetailed) {
		// TODO Auto-generated method stub
		getHibernateTemplate().save(flowDetailed);
	}

	
	public PageResult queryFaQiWorkExec(Map<String, String> filterMap) {
			StringBuffer queryString = new StringBuffer();
			StringBuffer queryCountString = new StringBuffer();
			
			queryString.append(" SELECT T.ID," +
							   " T1.FLOWNAME, "+
						       " T.FLOW_NAME,"+
						       " T.FLOW_TYPE_ID,"+
						       " t.FLOW_STATE_ID,"+
						       " t.FLOW_STATE_NAME,"+
						       " T.FLOW_ACTION_TYPE,"+
						       " t2.NEXT_ROLES_ID,"+
						       " t2.NEXT_ROLES_NAME,"+
						       " t2.NEXT_USERS_ID,"+
						       " t2.NEXT_USERS_NAME,"+
						       " T.ADD_TIME,"+
						       " T.ADD_USER_ID,"+
						       " T.ADD_USER_NAME,"+
						       " T2.ID as flowtaskinfoid,T.MAIN_ID "+
						  	   " FROM FLOW_TASK T LEFT JOIN flow_flowtype t1 ON t.flow_type_id = t1.id" +
						  	   " left join FLOW_TASK_INFO t2 ON t.ID=t2.flow_task_id " +
						  	   " where  t.state=5 and (t2.state is null or t2.state<>1)");
			if (filterMap != null && !filterMap.isEmpty()) {
				if(null != filterMap.get("state") &&! "".equals(filterMap.get("state"))){
					queryString.append(" and t2.state="+filterMap.get("state"));
				}

				if(null != filterMap.get("userId") &&! "".equals(filterMap.get("userId"))){
					queryString.append(" and T.ADD_USER_ID = '"+filterMap.get("userId")+"' ");
				}

//				if(null != filterMap.get("deptId") &&! "".equals(filterMap.get("deptId"))){
//					queryString.append(" and (t2.next_dept_id="+filterMap.get("deptId")+" or t2.next_dept_id is null)");
//				}
				if(null != filterMap.get("flowtype") &&! "".equals(filterMap.get("flowtype"))){
					queryString.append(" and t1.FLOWNAME like '%").append(filterMap.get("flowtype")).append("%' ");
				}
				if(null != filterMap.get("flowname") &&! "".equals(filterMap.get("flowname"))){
					queryString.append(" and t.FLOW_NAME like '%").append(filterMap.get("flowname")).append("%' ");
				}
				if(null != filterMap.get("type") && "start".equals(filterMap.get("type"))){
					queryString.append(" and T.FLOW_TYPE_ID="+filterMap.get("flowid"));
				}
				else
				{
					queryString.append(" and t2.flow_state_id != 'end' and t2.flow_state_id !='baofei' ");
				}
				
				String sidx = (String) filterMap.get("sidx");
				String sord = (String) filterMap.get("sord");
				queryString.append(" order by t.add_time desc  ");
			}
			queryCountString.append(" SELECT COUNT(*) from ("+queryString.toString()+" )   ");
			return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
		}

	
	public List<Flowtype> getFlowtypeList() {
		String hql = "from Flowtype";
		return this.getHibernateTemplate().find(hql);

	}

	
	public List getStandardList() {
		String hql = "from DicStandard";
		return this.getHibernateTemplate().find(hql);
	}

	
	public void changeCftdmUngentExec(String id) {System.out.print("22");
		  String sql = " update Flow_Task set urgent ='加急' where id = "+id+"";
			Query query = getSession().createSQLQuery(sql);
			query.executeUpdate();
	}

	
	public void changeFlowTaskUngentExec(String id) {System.out.print("11");
		String sql = " update Cf_Tdm t1 set t1.whetherjj ='加急' where t1.id =(select t.main_Id from Flow_Task t where t.id = "+id+" )";
		Query query = getSession().createSQLQuery(sql);
		query.executeUpdate();
	}
	
	public PageResult queryRationalizeDataList(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append(" SELECT COUNT(*) FROM (   select distinct  t.id ,t.T_CLPH,t.t_jstj,t2.SAMPLE_NO,T_JYXM,t.rclry,t.rclsj,t.jgwcqkry,t.jgwcqksj,t.jgshrqry,t.jgshrqsj, t.ITEMRESULT, t.T_PDYJ, S.USERNAME,t.proc2_state,t.proc2_time, t.sjjd_user,t.sjjd_state,t.sjjd_time,t.proc7_user,t.proc7_state,t.proc7_time,t.shbg_user,t.shbg_state, t.shbg_time,t.pzbg_user,t.pzbg_state,t.pzbg_time,t.proc3_user,t.proc3_state, t.proc3_time,t.T_YSJLPATH, t.BG_PATH,t.HUIZONGBG_PATH  from tdm_flow_item t left join cf_tdm t1 on t.flow_main_id = t1.id   left join flow_task t3 on t3.main_id = t1.id    left join flow_detailed t4 on t4.flow_task_id = t3.id left join tdm_sample t2 on t2.id = t.sample_id LEFT JOIN SYS_USERS S ON S.USERID=T.USER_ID where   t1.TEST_NO='"+filterMap.get("testNo")+"' ");
		queryString.append(" select distinct  t.id,t.T_CLPH,t.t_jstj,t2.SAMPLE_NO,T_JYXM, t.rclry,t.rclsj,t.jgwcqkry,t.jgwcqksj,t.jgshrqry,t.jgshrqsj,t.ITEMRESULT, t.T_PDYJ, S.USERNAME,t.proc2_state,t.proc2_time, t.sjjd_user,t.sjjd_state,t.sjjd_time,t.proc7_user,t.proc7_state,t.proc7_time,t.shbg_user,t.shbg_state, t.shbg_time,t.pzbg_user,t.pzbg_state,t.pzbg_time,t.proc3_user,t.proc3_state, t.proc3_time,t.T_YSJLPATH, t.BG_PATH,t.HUIZONGBG_PATH  from tdm_flow_item t left join cf_tdm t1 on t.flow_main_id = t1.id left join flow_task t3 on t3.main_id = t1.id    left join flow_detailed t4 on t4.flow_task_id = t3.id left join tdm_sample t2 on t2.id = t.sample_id LEFT JOIN SYS_USERS S ON S.USERID=T.USER_ID where t1.TEST_NO='"+filterMap.get("testNo")+"' ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if( "1".equals(filterMap.get("wczt"))){
				queryString.append(" and t4.statusafter = '结束' ");
				queryCountString.append(" and t4.statusafter = '结束' ");
			}
			if(null != filterMap.get("WEITUODANWEI") &&! "".equals(filterMap.get("WEITUODANWEI"))){
				queryString.append(" and t1.WEITUODANWEI like '%").append(filterMap.get("WEITUODANWEI")).append("%' ");
				queryCountString.append(" and t1.WEITUODANWEI like '%").append(filterMap.get("WEITUODANWEI")).append("%' ");
			}
			if(null != filterMap.get("TEST_NO") &&! "".equals(filterMap.get("TEST_NO"))){
				queryString.append(" and t1.TEST_NO like '%").append(filterMap.get("TEST_NO")).append("%' ");
				queryCountString.append(" and t1.TEST_NO like '%").append(filterMap.get("TEST_NO")).append("%' ");
			}

			if(filterMap.get("WEITUORIQ")!=null && !"".equals(filterMap.get("WEITUORIQ"))){
				queryString.append(" and t1.WEITUORIQ >= '"+filterMap.get("WEITUORIQ")+"'");
				queryCountString.append(" and t1.WEITUORIQ >= '"+filterMap.get("WEITUORIQ")+"'");
			}
			if(filterMap.get("WEITUORIQTO")!=null && !"".equals(filterMap.get("WEITUORIQTO"))){
				queryString.append(" and t1.WEITUORIQ<= '"+filterMap.get("WEITUORIQTO")+"'");
				queryCountString.append(" and t1.WEITUORIQ <= '"+filterMap.get("WEITUORIQTO")+"'");
			}
			if(null != filterMap.get("T_JSTJ") &&! "".equals(filterMap.get("T_JSTJ"))){
				queryString.append(" and t.T_JYXM like '%").append(filterMap.get("T_JSTJ")).append("%' ");
				queryCountString.append(" and t.T_JYXM like '%").append(filterMap.get("T_JSTJ")).append("%' ");
			}
			if(null != filterMap.get("WEITUOBIANHAO") &&! "".equals(filterMap.get("WEITUOBIANHAO"))){
				queryString.append(" and t1.WEITUOBIANHAO like '%").append(filterMap.get("WEITUOBIANHAO")).append("%' ");
				queryCountString.append(" and t1.WEITUOBIANHAO like '%").append(filterMap.get("WEITUOBIANHAO")).append("%' ");
			}
			if(null != filterMap.get("TDM_GUIGE") && !"".equals(filterMap.get("TDM_GUIGE"))){
				queryString.append(" and t1.TDM_GUIGE like '%").append(filterMap.get("TDM_GUIGE")).append("%' ");
				queryCountString.append(" and t1.TDM_GUIGE like '%").append(filterMap.get("TDM_GUIGE")).append("%' ");
			}
			if(null != filterMap.get("TDM_CAILIAOPAIHAO") &&! "".equals(filterMap.get("TDM_CAILIAOPAIHAO"))){
				queryString.append(" and t.t_clph like '%").append(filterMap.get("TDM_CAILIAOPAIHAO")).append("%' ");
				queryCountString.append(" and t.t_clph like '%").append(filterMap.get("TDM_CAILIAOPAIHAO")).append("%' ");
			}
			
			if(null != filterMap.get("LINGJIANMINGC") &&! "".equals(filterMap.get("LINGJIANMINGC"))){
				queryString.append(" and t1.LINGJIANMINGC like '%").append(filterMap.get("LINGJIANMINGC")).append("%' ");
				queryCountString.append(" and t1.LINGJIANMINGC like '%").append(filterMap.get("LINGJIANMINGC")).append("%' ");
			}

			if(null != filterMap.get("LINGJIANTUHAO") &&! "".equals(filterMap.get("LINGJIANTUHAO"))){
				queryString.append(" and t1.LINGJIANTUHAO like '%").append(filterMap.get("LINGJIANTUHAO")).append("%' ");
				queryCountString.append(" and t1.LINGJIANTUHAO like '%").append(filterMap.get("LINGJIANTUHAO")).append("%' ");
			}
			
			if(null != filterMap.get("LUHAO") &&! "".equals(filterMap.get("LUHAO"))){
				queryString.append(" and t1.LUHAO like '%").append(filterMap.get("LUHAO")).append("%' ");
				queryCountString.append(" and t1.LUHAO like '%").append(filterMap.get("LUHAO")).append("%' ");
			}
			if(null != filterMap.get("PIHAO") &&! "".equals(filterMap.get("PIHAO"))){
				queryString.append(" and t1.PIHAO like '%").append(filterMap.get("PIHAO")).append("%' ");
				queryCountString.append(" and t1.PIHAO like '%").append(filterMap.get("PIHAO")).append("%' ");
			}
			if(null != filterMap.get("PLACE") && !"".equals(filterMap.get("PLACE"))){
				queryString.append(" and t1.PLACE like '%").append(filterMap.get("PLACE")).append("%' ");
				queryCountString.append(" and t1.PLACE like '%").append(filterMap.get("PLACE")).append("%' ");
			}
			if(null != filterMap.get("JISHUTIAOJIAN") &&! "".equals(filterMap.get("JISHUTIAOJIAN"))){
				queryString.append(" and t.t_jstj like '%").append(filterMap.get("JISHUTIAOJIAN")).append("%' ");
				queryCountString.append(" and t.t_jstj like '%").append(filterMap.get("JISHUTIAOJIAN")).append("%' ");
			}
			
			if(null != filterMap.get("T_XMZ") &&! "".equals(filterMap.get("T_XMZ"))){
				queryString.append(" and t.T_XMZ like '%").append(filterMap.get("T_XMZ")).append("%' ");
				queryCountString.append(" and t.T_XMZ like '%").append(filterMap.get("T_XMZ")).append("%' ");
			}

			if(null != filterMap.get("BAOGAOHAO") &&! "".equals(filterMap.get("BAOGAOHAO"))){
				queryString.append(" and t1.BAOGAOHAO like '%").append(filterMap.get("BAOGAOHAO")).append("%' ");
				queryCountString.append(" and t1.BAOGAOHAO like '%").append(filterMap.get("BAOGAOHAO")).append("%' ");
			}
			if(null != filterMap.get("T_PDYJ") &&! "".equals(filterMap.get("T_PDYJ"))){
				queryString.append(" and t.T_PDYJ like '%").append(filterMap.get("T_PDYJ")).append("%' ");
				queryCountString.append(" and t.T_PDYJ like '%").append(filterMap.get("T_PDYJ")).append("%' ");
			}
			if(null != filterMap.get("T_JCS") &&! "".equals(filterMap.get("T_JCS"))){
				queryString.append(" and t.T_JCS like '%").append(filterMap.get("T_JCS")).append("%' ");
				queryCountString.append(" and t.T_JCS like '%").append(filterMap.get("T_JCS")).append("%' ");
			}
			if(null != filterMap.get("step") &&! "".equals(filterMap.get("step"))){
				queryString.append(" and t1.test_id in ("+filterMap.get("step")+") ");
				queryCountString.append(" and t1.test_id in ("+filterMap.get("step")+") ");
			}
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append(" order by id desc  ");
			queryCountString.append(" order by id desc ");
			queryCountString.append(" ) ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	
	public List findRationData(Map filterMap) {
		StringBuffer sql = new StringBuffer();
		
		sql.append(" select distinct t.id, t.weituodanwei,t.WEITUORIQ,t.weituobianhao,t.test_no,t.TDM_CAILIAOPAIHAO,t1.T_JSTJ,t2.sample_name, "+
               " t1.T_JYXM,t1.rclry,t1.rclsj,t1.jgwcqkry,t1.jgwcqksj,t1.jgshrqry,t1.jgshrqsj,t1.ITEMRESULT,t1.T_PDYJ,t.ANALYSE_USER,t.ANALYSE_TIME,t.check_user,t.check_time,t.report_user, "+
               "  t.report_time,t.reportcheck_user,t.reportcheck_time,t.approval_user,t.approval_time,t.reportsummary_user,t.reportsummary_time,t1.t_ysjlpath,t1.bg_path,t1.huizongbg_path from cf_tdm t left join flow_task t3 on t3.main_id = t.id    left join flow_detailed t4 on t4.flow_task_id = t3.id left join tdm_flow_item t1 on t1.flow_main_id=t.id "+
               " left join tdm_sample t2 on t2.id = t1.sample_id where 1=1 ");
		if (filterMap != null && !filterMap.isEmpty()) {
			
				if("1".equals(filterMap.get("wczt"))){
					sql.append(" and t4.statusafter = '结束' ");
				}
				if(null != filterMap.get("WEITUODANWEI") &&! "".equals(filterMap.get("WEITUODANWEI"))){
					sql.append(" and t.WEITUODANWEI like '%").append(filterMap.get("WEITUODANWEI")).append("%' ");
				}
				
				if(null != filterMap.get("TEST_NO") &&! "".equals(filterMap.get("TEST_NO"))){
					sql.append(" and t.TEST_NO like '%").append(filterMap.get("TEST_NO")).append("%' ");
				}

				if(null != filterMap.get("WEITUORIQ") &&! "".equals(filterMap.get("WEITUORIQ"))){
					sql.append(" and t.WEITUORIQ like '%").append(filterMap.get("WEITUORIQ")).append("%' ");
				}
				if(null != filterMap.get("T_JSTJ") &&! "".equals(filterMap.get("T_JSTJ"))){
					sql.append(" and t1.t_jstj like '%").append(filterMap.get("T_JSTJ")).append("%' ");
				}
				if(null != filterMap.get("WEITUOBIANHAO") &&! "".equals(filterMap.get("WEITUOBIANHAO"))){
					sql.append(" and t.WEITUOBIANHAO like '%").append(filterMap.get("WEITUOBIANHAO")).append("%' ");
				}
				if(null != filterMap.get("TDM_GUIGE") && !"".equals(filterMap.get("TDM_GUIGE"))){
					sql.append(" and t.TDM_GUIGE like '%").append(filterMap.get("TDM_GUIGE")).append("%' ");
				}
				if(null != filterMap.get("TDM_CAILIAOPAIHAO") &&! "".equals(filterMap.get("TDM_CAILIAOPAIHAO"))){
					sql.append(" and t.TDM_CAILIAOPAIHAO like '%").append(filterMap.get("TDM_CAILIAOPAIHAO")).append("%' ");
				}
				
				if(null != filterMap.get("LINGJIANMINGC") &&! "".equals(filterMap.get("LINGJIANMINGC"))){
					sql.append(" and t.LINGJIANMINGC like '%").append(filterMap.get("LINGJIANMINGC")).append("%' ");
				}

				if(null != filterMap.get("LINGJIANTUHAO") &&! "".equals(filterMap.get("LINGJIANTUHAO"))){
					sql.append(" and t.LINGJIANTUHAO like '%").append(filterMap.get("LINGJIANTUHAO")).append("%' ");
				}
				
				if(null != filterMap.get("LUHAO") &&! "".equals(filterMap.get("LUHAO"))){
					sql.append(" and t.LUHAO like '%").append(filterMap.get("LUHAO")).append("%' ");
				}
				if(null != filterMap.get("PIHAO") &&! "".equals(filterMap.get("PIHAO"))){
					sql.append(" and t.PIHAO like '%").append(filterMap.get("PIHAO")).append("%' ");
				}
				if(null != filterMap.get("PLACE") && "start".equals(filterMap.get("PLACE"))){
					sql.append(" and t.PLACE like '%").append(filterMap.get("PLACE")).append("%' ");
				}
				if(null != filterMap.get("JISHUTIAOJIAN") &&! "".equals(filterMap.get("JISHUTIAOJIAN"))){
					sql.append(" and t1.t_jstj like '%").append(filterMap.get("JISHUTIAOJIAN")).append("%' ");
				}
				
				if(null != filterMap.get("T_XMZ") &&! "".equals(filterMap.get("T_XMZ"))){
					sql.append(" and t1.T_XMZ like '%").append(filterMap.get("T_XMZ")).append("%' ");
				}

				if(null != filterMap.get("BAOGAOHAO") &&! "".equals(filterMap.get("BAOGAOHAO"))){
					sql.append(" and t.BAOGAOHAO like '%").append(filterMap.get("BAOGAOHAO")).append("%' ");
				}
				if(null != filterMap.get("T_PDYJ") &&! "".equals(filterMap.get("T_PDYJ"))){
					sql.append(" and t1.T_PDYJ like '%").append(filterMap.get("T_PDYJ")).append("%' ");
				}
				if(null != filterMap.get("T_JCS") &&! "".equals(filterMap.get("T_JCS"))){
					sql.append(" and t1.T_JCS like '%").append(filterMap.get("T_JCS")).append("%' ");
				}
			
		}
		Query query = this.getSession().createSQLQuery(sql.toString());
		List list = query.list();
		getSession().clear();
		return list;
	}
	
	public List findFlowTaskList(String string) {
		String sql = " select t.id,t.flow_type_id,t.main_flow_id from FLOW_TASK t where t.shiyanbh='"+string+"' ";
		Query query = this.getSession().createSQLQuery(sql);
		List list = query.list();
		getSession().clear();
		return list;
	}
	
	public PageResult queryRationalizeDataZongList(Map<String, String> filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		queryCountString.append(" SELECT COUNT(*) FROM (   select distinct t1.test_no ,t1.weituodanwei,t1.WEITUORIQ,t1.weituobianhao  from tdm_flow_item t left join cf_tdm t1 on t.flow_main_id = t1.id   left join flow_task t3 on t3.main_id = t1.id    left join flow_detailed t4 on t4.flow_task_id = t3.id left join tdm_sample t2 on t2.id = t.sample_id LEFT JOIN SYS_USERS S ON S.USERID=T.USER_ID where 1 = 1");
		queryString.append(" select distinct  t1.test_no ,t1.weituodanwei,t1.WEITUORIQ,t1.weituobianhao from tdm_flow_item t left join cf_tdm t1 on t.flow_main_id = t1.id left join flow_task t3 on t3.main_id = t1.id    left join flow_detailed t4 on t4.flow_task_id = t3.id left join tdm_sample t2 on t2.id = t.sample_id LEFT JOIN SYS_USERS S ON S.USERID=T.USER_ID where 1 = 1 ");
		if (filterMap != null && !filterMap.isEmpty()) {
			if( "1".equals(filterMap.get("wczt"))){
				queryString.append(" and t4.statusafter = '结束' ");
				queryCountString.append(" and t4.statusafter = '结束' ");
			}
			if(null != filterMap.get("init") &&! "".equals(filterMap.get("init"))){
				queryString.append(" and t1.WEITUODANWEI = '").append(filterMap.get("init")).append("' ");
				queryCountString.append(" and t1.WEITUODANWEI = '").append(filterMap.get("init")).append("'");
			}
			if(null != filterMap.get("WEITUODANWEI") &&! "".equals(filterMap.get("WEITUODANWEI"))){
				queryString.append(" and t1.WEITUODANWEI like '%").append(filterMap.get("WEITUODANWEI")).append("%' ");
				queryCountString.append(" and t1.WEITUODANWEI like '%").append(filterMap.get("WEITUODANWEI")).append("%' ");
			}
			if(null != filterMap.get("TEST_NO") &&! "".equals(filterMap.get("TEST_NO"))){
				queryString.append(" and t1.TEST_NO like '%").append(filterMap.get("TEST_NO")).append("%' ");
				queryCountString.append(" and t1.TEST_NO like '%").append(filterMap.get("TEST_NO")).append("%' ");
			}

			if(filterMap.get("WEITUORIQ")!=null && !"".equals(filterMap.get("WEITUORIQ"))){
				queryString.append(" and t1.WEITUORIQ >= '"+filterMap.get("WEITUORIQ")+"'");
				queryCountString.append(" and t1.WEITUORIQ >= '"+filterMap.get("WEITUORIQ")+"'");
			}
			if(filterMap.get("WEITUORIQTO")!=null && !"".equals(filterMap.get("WEITUORIQTO"))){
				queryString.append(" and t1.WEITUORIQ<= '"+filterMap.get("WEITUORIQTO")+"'");
				queryCountString.append(" and t1.WEITUORIQ <= '"+filterMap.get("WEITUORIQTO")+"'");
			}
			if(null != filterMap.get("T_JSTJ") &&! "".equals(filterMap.get("T_JSTJ"))){
				queryString.append(" and t.T_JYXM like '%").append(filterMap.get("T_JSTJ")).append("%' ");
				queryCountString.append(" and t.T_JYXM like '%").append(filterMap.get("T_JSTJ")).append("%' ");
			}
			if(null != filterMap.get("WEITUOBIANHAO") &&! "".equals(filterMap.get("WEITUOBIANHAO"))){
				queryString.append(" and t1.WEITUOBIANHAO like '%").append(filterMap.get("WEITUOBIANHAO")).append("%' ");
				queryCountString.append(" and t1.WEITUOBIANHAO like '%").append(filterMap.get("WEITUOBIANHAO")).append("%' ");
			}
			if(null != filterMap.get("TDM_GUIGE") && !"".equals(filterMap.get("TDM_GUIGE"))){
				queryString.append(" and t1.TDM_GUIGE like '%").append(filterMap.get("TDM_GUIGE")).append("%' ");
				queryCountString.append(" and t1.TDM_GUIGE like '%").append(filterMap.get("TDM_GUIGE")).append("%' ");
			}
			if(null != filterMap.get("TDM_CAILIAOPAIHAO") &&! "".equals(filterMap.get("TDM_CAILIAOPAIHAO"))){
				queryString.append(" and t.t_clph like '%").append(filterMap.get("TDM_CAILIAOPAIHAO")).append("%' ");
				queryCountString.append(" and t.t_clph like '%").append(filterMap.get("TDM_CAILIAOPAIHAO")).append("%' ");
			}
			
			if(null != filterMap.get("LINGJIANMINGC") &&! "".equals(filterMap.get("LINGJIANMINGC"))){
				queryString.append(" and t1.LINGJIANMINGC like '%").append(filterMap.get("LINGJIANMINGC")).append("%' ");
				queryCountString.append(" and t1.LINGJIANMINGC like '%").append(filterMap.get("LINGJIANMINGC")).append("%' ");
			}

			if(null != filterMap.get("LINGJIANTUHAO") &&! "".equals(filterMap.get("LINGJIANTUHAO"))){
				queryString.append(" and t1.LINGJIANTUHAO like '%").append(filterMap.get("LINGJIANTUHAO")).append("%' ");
				queryCountString.append(" and t1.LINGJIANTUHAO like '%").append(filterMap.get("LINGJIANTUHAO")).append("%' ");
			}
			
			if(null != filterMap.get("LUHAO") &&! "".equals(filterMap.get("LUHAO"))){
				queryString.append(" and t1.LUHAO like '%").append(filterMap.get("LUHAO")).append("%' ");
				queryCountString.append(" and t1.LUHAO like '%").append(filterMap.get("LUHAO")).append("%' ");
			}
			if(null != filterMap.get("PIHAO") &&! "".equals(filterMap.get("PIHAO"))){
				queryString.append(" and t1.PIHAO like '%").append(filterMap.get("PIHAO")).append("%' ");
				queryCountString.append(" and t1.PIHAO like '%").append(filterMap.get("PIHAO")).append("%' ");
			}
			if(null != filterMap.get("PLACE") && !"".equals(filterMap.get("PLACE"))){
				queryString.append(" and t1.PLACE like '%").append(filterMap.get("PLACE")).append("%' ");
				queryCountString.append(" and t1.PLACE like '%").append(filterMap.get("PLACE")).append("%' ");
			}
			if(null != filterMap.get("JISHUTIAOJIAN") &&! "".equals(filterMap.get("JISHUTIAOJIAN"))){
				queryString.append(" and t.t_jstj like '%").append(filterMap.get("JISHUTIAOJIAN")).append("%' ");
				queryCountString.append(" and t.t_jstj like '%").append(filterMap.get("JISHUTIAOJIAN")).append("%' ");
			}
			
			if(null != filterMap.get("T_XMZ") &&! "".equals(filterMap.get("T_XMZ"))){
				queryString.append(" and t.T_XMZ like '%").append(filterMap.get("T_XMZ")).append("%' ");
				queryCountString.append(" and t.T_XMZ like '%").append(filterMap.get("T_XMZ")).append("%' ");
			}

			if(null != filterMap.get("BAOGAOHAO") &&! "".equals(filterMap.get("BAOGAOHAO"))){
				queryString.append(" and t1.BAOGAOHAO like '%").append(filterMap.get("BAOGAOHAO")).append("%' ");
				queryCountString.append(" and t1.BAOGAOHAO like '%").append(filterMap.get("BAOGAOHAO")).append("%' ");
			}
			if(null != filterMap.get("T_PDYJ") &&! "".equals(filterMap.get("T_PDYJ"))){
				queryString.append(" and t.T_PDYJ like '%").append(filterMap.get("T_PDYJ")).append("%' ");
				queryCountString.append(" and t.T_PDYJ like '%").append(filterMap.get("T_PDYJ")).append("%' ");
			}
			if(null != filterMap.get("T_JCS") &&! "".equals(filterMap.get("T_JCS"))){
				queryString.append(" and t.T_JCS like '%").append(filterMap.get("T_JCS")).append("%' ");
				queryCountString.append(" and t.T_JCS like '%").append(filterMap.get("T_JCS")).append("%' ");
			}
			if(null != filterMap.get("step") &&! "".equals(filterMap.get("step"))){
				queryString.append(" and t1.test_id in ("+filterMap.get("step")+") ");
				queryCountString.append(" and t1.test_id in ("+filterMap.get("step")+") ");
			}
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append(" order by t1.test_no desc  ");
			queryCountString.append(" order by t1.test_no desc ");
			queryCountString.append(" ) ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	/*
	 * 查询流程状态及数量   一般、加急、延期
	 * wxj
	 */
	public List queryFlowtaskType(Map filterMap){
		StringBuffer queryCountString = new StringBuffer();
		List list = null;
		if (filterMap != null && !filterMap.isEmpty()) {
			String type = filterMap.get("flag").toString();
			if(null != type &&! "".equals(type)){
					queryCountString.append(" SELECT COUNT(*) FROM ( SELECT distinct t2.ID," +//研发检测流程
							   " T1.FLOWNAME, "+
						       " T.FLOW_NAME,"+
						       " T.FLOW_TYPE_ID,"+
						       " t2.FLOW_STATE_ID,"+
						       " t2.FLOW_STATE_NAME,"+
						       " T.FLOW_ACTION_TYPE,"+
						       " T.MAIN_ID,"+
						       " t2.NEXT_ROLES_ID,"+
						       " t2.NEXT_ROLES_NAME,"+
						       " t2.NEXT_USERS_ID,"+
						       " t2.NEXT_USERS_NAME,"+
						       " T.ADD_TIME,"+
						       " T.ADD_USER_ID,"+
						       " T.ADD_USER_NAME,T.ID taskId"+
						       ",y.weituodanshibieno,y.LIANXIREN,y.SHENQINGRIQI,y.RENWUNAME"+
						  	   " FROM FLOW_TASK T LEFT JOIN flow_flowtype t1 ON t.flow_type_id = t1.id " +
						  	   " left join flow_task_info t2 on t.id=t2.flow_task_id" +
						  	   " left join GWM_YANFAJIANCE y "+
						  	   " on t.main_id = y.id and t.table_name='GWM_YANFAJIANCE' "+
						  	   " where t.flow_type_id = '2241' and t.flow_state_id != 'wait'  and t.flow_state_id !='finish' and t2.state=0 " );
			if (filterMap != null && !filterMap.isEmpty()) {
				if(null != filterMap.get("type") && "start".equals(filterMap.get("type"))){
					queryCountString.append(" and T.FLOW_TYPE_ID="+filterMap.get("flowid"));
				}
				else
				{
					queryCountString.append(" and t.flow_state_id != 'end'  and t2.flow_state_id != 'end'  ");
				}
				if(null != filterMap.get("id")&&!"".equals(filterMap.get("id"))){
					queryCountString.append(" and T.ID in("+filterMap.get("id") + ")");
				}
				String rids = (String) filterMap.get("roleId");
				String[] roleIds = rids.split(",");
				queryCountString.append(" and (");
				for (int i = 0; i < roleIds.length; i++) {
					if(roleIds.length > 1){
						if(i == roleIds.length - 1){
							queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%'");
						}else{
							queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%' or");
						}
					}else{
						queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%'");
					}
				}
				
				queryCountString.append(" or (t2.next_users_id like '%," +filterMap.get("userId") + ",%' and t2.next_roles_id is  null ) )");
				if(null != filterMap.get("deptId") &&! "".equals(filterMap.get("deptId"))){
					queryCountString.append(" and (t2.next_dept_id= '"+filterMap.get("deptId")+"' or t2.next_dept_id is null)");
					
				}
				if("0".equals(type)){ //一般流程
					queryCountString.append(" and (trunc(to_date(y.SHUANGFANGYUEDINGRIQI,'yyyy-mm-dd')-to_date(TO_CHAR(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'))>3  or y.SHUANGFANGYUEDINGRIQI is null) ");
				}else if("1".equals(type)){//加急流程
					queryCountString.append(" and trunc(to_date(y.SHUANGFANGYUEDINGRIQI,'yyyy-mm-dd')-to_date(TO_CHAR(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'))<=3 and  trunc(to_date(y.SHUANGFANGYUEDINGRIQI,'yyyy-mm-dd')-to_date(TO_CHAR(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'))>=0");
				}else if("2".equals(type)){//延期流程
					queryCountString.append(" and trunc(to_date(y.SHUANGFANGYUEDINGRIQI,'yyyy-mm-dd')-to_date(TO_CHAR(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'))<0 ");
				}
				
			}
			queryCountString.append(" union ");
			queryCountString.append(" SELECT distinct t2.ID," +//整车可靠性试验流程
					   " T1.FLOWNAME, "+
				       " T.FLOW_NAME,"+
				       " T.FLOW_TYPE_ID,"+
				       " t2.FLOW_STATE_ID,"+
				       " t2.FLOW_STATE_NAME,"+
				       " T.FLOW_ACTION_TYPE,"+
				       " T.MAIN_ID,"+
				       " t2.NEXT_ROLES_ID,"+
				       " t2.NEXT_ROLES_NAME,"+
				       " t2.NEXT_USERS_ID,"+
				       " t2.NEXT_USERS_NAME,"+
				       " T.ADD_TIME,"+
				       " T.ADD_USER_ID,"+
				       " T.ADD_USER_NAME,T.ID taskId,w.WEITUODANSHIBIENO,w.LIANXIREN,w.SHENQINGDATE,w.RENWUNAME "+
				  	   " FROM FLOW_TASK T LEFT JOIN flow_flowtype t1 ON t.flow_type_id = t1.id " +
				  	   " left join flow_task_info t2 on t.id=t2.flow_task_id" +
				  	   " left join GWM_WEITUODAN w on t.main_id = w.id and t.table_name='GWM_WEITUODAN'"+
				  	   " where t.flow_type_id = '2181' and t.flow_state_id != 'wait'  and t.flow_state_id !='finish' and t2.state=0 " );
			if (filterMap != null && !filterMap.isEmpty()) {
				if(null != filterMap.get("type") && "start".equals(filterMap.get("type"))){
					queryCountString.append(" and T.FLOW_TYPE_ID="+filterMap.get("flowid"));
				}
				else
				{
					queryCountString.append(" and t.flow_state_id != 'end'  and t2.flow_state_id != 'end'  ");
				}
				if(null != filterMap.get("id")&&!"".equals(filterMap.get("id"))){
					queryCountString.append(" and T.ID in("+filterMap.get("id") + ")");
				}
				String rids = (String) filterMap.get("roleId");
				String[] roleIds = rids.split(",");
				queryCountString.append(" and (");
				for (int i = 0; i < roleIds.length; i++) {
					if(roleIds.length > 1){
						if(i == roleIds.length - 1){
							queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%'");
						}else{
							queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%' or");
						}
					}else{
						queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%'");
					}
				}
				
				queryCountString.append(" or (t2.next_users_id like '%," +filterMap.get("userId") + ",%' and t2.next_roles_id is  null ) )");
				if(null != filterMap.get("deptId") &&! "".equals(filterMap.get("deptId"))){
					queryCountString.append(" and (t2.next_dept_id= '"+filterMap.get("deptId")+"' or t2.next_dept_id is null)");
					
				}
				if("0".equals(type)){ //一般流程
					queryCountString.append(" and (trunc(to_date(w.shuangfangyuedingdate,'yyyy-mm-dd')-to_date(TO_CHAR(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'))>3 or w.shuangfangyuedingdate is null) ");
				}else if("1".equals(type)){//加急流程
					queryCountString.append(" and trunc(to_date(w.shuangfangyuedingdate,'yyyy-mm-dd')-to_date(TO_CHAR(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'))<=3 and  trunc(to_date(w.shuangfangyuedingdate,'yyyy-mm-dd')-to_date(TO_CHAR(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'))>=0");
				}else if("2".equals(type)){//延期流程
					queryCountString.append(" and trunc(to_date(w.shuangfangyuedingdate,'yyyy-mm-dd')-to_date(TO_CHAR(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'))<0 ");
				}
				
			}
			queryCountString.append(" union ");
			queryCountString.append(" SELECT distinct t2.ID," +
					   " T1.FLOWNAME, "+
				       " T.FLOW_NAME,"+
				       " T.FLOW_TYPE_ID,"+
				       " t2.FLOW_STATE_ID,"+
				       " t2.FLOW_STATE_NAME,"+
				       " T.FLOW_ACTION_TYPE,"+
				       " T.MAIN_ID,"+
				       " t2.NEXT_ROLES_ID,"+
				       " t2.NEXT_ROLES_NAME,"+
				       " t2.NEXT_USERS_ID,"+
				       " t2.NEXT_USERS_NAME,"+
				       " T.ADD_TIME,"+
				       " T.ADD_USER_ID,"+
				       " T.ADD_USER_NAME,T.ID taskId,c.T_WEITUODANBH,c.T_LIANXIREN,c.T_SHENQINGRQ,c.T_TESTNAME"+
				  	   " FROM FLOW_TASK T LEFT JOIN flow_flowtype t1 ON t.flow_type_id = t1.id " +
				  	   " left join flow_task_info t2 on t.id=t2.flow_task_id" +
				  	   " left join GWM_CHANGGIJIANCE c on t.main_id = c.id and t.table_name='GWM_CHANGGIJIANCE'"+
				  	   " where t.flow_type_id = '2121' and t.flow_state_id != 'wait'  and t.flow_state_id !='finish' and t2.state=0 " );
			if (filterMap != null && !filterMap.isEmpty()) {
				if(null != filterMap.get("type") && "start".equals(filterMap.get("type"))){
					queryCountString.append(" and T.FLOW_TYPE_ID="+filterMap.get("flowid"));
				}
				else
				{
					queryCountString.append(" and t.flow_state_id != 'end'  and t2.flow_state_id != 'end'  ");
				}
				if(null != filterMap.get("id")&&!"".equals(filterMap.get("id"))){
					queryCountString.append(" and T.ID in("+filterMap.get("id") + ")");
				}
				String rids = (String) filterMap.get("roleId");
				String[] roleIds = rids.split(",");
				queryCountString.append(" and (");
				for (int i = 0; i < roleIds.length; i++) {
					if(roleIds.length > 1){
						if(i == roleIds.length - 1){
							queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%'");
						}else{
							queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%' or");
						}
					}else{
						queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%'");
					}
				}
				
				queryCountString.append(" or (t2.next_users_id like '%," +filterMap.get("userId") + ",%' and t2.next_roles_id is  null ) )");
				if(null != filterMap.get("deptId") &&! "".equals(filterMap.get("deptId"))){
					queryCountString.append(" and (t2.next_dept_id= '"+filterMap.get("deptId")+"' or t2.next_dept_id is null)");
					
				}
				if("0".equals(type)){ //一般流程
					queryCountString.append(" and (trunc(to_date(c.T_YUEDINGRIQI,'yyyy-mm-dd')-to_date(TO_CHAR(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'))>3 or c.T_YUEDINGRIQI is null) ");
				}else if("1".equals(type)){//加急流程
					queryCountString.append(" and trunc(to_date(c.T_YUEDINGRIQI,'yyyy-mm-dd')-to_date(TO_CHAR(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'))<=3 and  trunc(to_date(c.T_YUEDINGRIQI,'yyyy-mm-dd')-to_date(TO_CHAR(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'))>=0");
				}else if("2".equals(type)){//延期流程
					queryCountString.append(" and trunc(to_date(c.T_YUEDINGRIQI,'yyyy-mm-dd')-to_date(TO_CHAR(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'))<0 ");
				}
				
			}
			if(!"0".equals(type)){
				
			}else{
				queryCountString.append(" union ");
				queryCountString.append(" SELECT distinct t2.ID," +
						   " T1.FLOWNAME, "+
					       " T.FLOW_NAME,"+
					       " T.FLOW_TYPE_ID,"+
					       " t2.FLOW_STATE_ID,"+
					       " t2.FLOW_STATE_NAME,"+
					       " T.FLOW_ACTION_TYPE,"+
					       " T.MAIN_ID,"+
					       " t2.NEXT_ROLES_ID,"+
					       " t2.NEXT_ROLES_NAME,"+
					       " t2.NEXT_USERS_ID,"+
					       " t2.NEXT_USERS_NAME,"+
					       " T.ADD_TIME,"+
					       " T.ADD_USER_ID,"+
					       " T.ADD_USER_NAME,T.ID taskId,'','','',''"+
					  	   " FROM FLOW_TASK T LEFT JOIN flow_flowtype t1 ON t.flow_type_id = t1.id " +
					  	   " left join flow_task_info t2 on t.id=t2.flow_task_id" +
					  	   " where t.flow_type_id != '2241' and t.flow_type_id != '2121' and t.flow_type_id != '2181' and t.flow_state_id != 'wait'  and t.flow_state_id !='finish' and t2.state=0 " );
				if (filterMap != null && !filterMap.isEmpty()) {
					if(null != filterMap.get("type") && "start".equals(filterMap.get("type"))){
						queryCountString.append(" and T.FLOW_TYPE_ID="+filterMap.get("flowid"));
					}
					else
					{
						queryCountString.append(" and t.flow_state_id != 'end'  and t2.flow_state_id != 'end'  ");
					}
					if(null != filterMap.get("id")&&!"".equals(filterMap.get("id"))){
						queryCountString.append(" and T.ID in("+filterMap.get("id") + ")");
					}
					String rids = (String) filterMap.get("roleId");
					String[] roleIds = rids.split(",");
					queryCountString.append(" and (");
					for (int i = 0; i < roleIds.length; i++) {
						if(roleIds.length > 1){
							if(i == roleIds.length - 1){
								queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%'");
							}else{
								queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%' or");
							}
						}else{
							queryCountString.append(" t2.next_roles_id like '%," + roleIds[i] + ",%'");
						}
					}
					
					queryCountString.append(" or (t2.next_users_id like '%," +filterMap.get("userId") + ",%' and t2.next_roles_id is  null ) )");
					if(null != filterMap.get("deptId") &&! "".equals(filterMap.get("deptId"))){
						queryCountString.append(" and (t2.next_dept_id= '"+filterMap.get("deptId")+"' or t2.next_dept_id is null)");
						
					}
					if(null != filterMap.get("rwmc")&&!"".equals(filterMap.get("rwmc"))){
						queryCountString.append(" and T.FLOW_NAME like '%"+filterMap.get("rwmc")+"%'");
					}
					if(null != filterMap.get("jdmc")&&!"".equals(filterMap.get("jdmc"))){
						queryCountString.append(" and t2.FLOW_STATE_NAME like '%"+filterMap.get("jdmc")+"%'");
					}
				}
			}
			queryCountString.append(")");
			Query query = getSession().createSQLQuery(queryCountString.toString());
			list = query.list();
			}
		}
		return list;
		
	}


	public PageResult queryYiban(Map<String, String> filterMap) {
		StringBuffer queryCountString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		queryString.append(" select * from ( ");
		queryString.append(" select t1.id as flowtaskinfoid,t1.flow_task_id as flowtaskid,t2.flow_type_id," +
				"t1.flow_state_id,t2.main_id,t3.renwubh,t3.chanpindh,t3.shiyanlx,t3.fuzher,t3.shiyandd,t3.shiyankssj," +
				"t3.yujijssj,t1.flow_state_name,t1.next_users_name,t2.add_user_name,t2.add_time from flow_task_info t1 " +
				"left join flow_task t2 on t1.flow_task_id=t2.id " +
				"left join kl_junyans t3 on t3.id=t2.main_id "+
				"where  t1.flow_state_id !='finish' and t1.flow_state_id != 'end' and t1.state=0 " +
				"and t2.id in (select flow_task_id from flow_detailed where OPERATORPERSON_ID='"+filterMap.get("userId")+"') " );
		if (filterMap != null && !filterMap.isEmpty()) {
			
			if(null != filterMap.get("renwubh")&&!"".equals(filterMap.get("renwubh"))){
				queryString.append(" and t3.renwubh like '%"+filterMap.get("renwubh")+"%'");
			}
			if(null != filterMap.get("chanpindh")&&!"".equals(filterMap.get("chanpindh"))){
				queryString.append(" and t3.chanpindh like '%"+filterMap.get("chanpindh")+"%'");
			}
			if(null != filterMap.get("shiyanlx")&&!"".equals(filterMap.get("shiyanlx"))){
				queryString.append(" and t3.shiyanlx like '%"+filterMap.get("shiyanlx")+"%'");
			}
			if(null != filterMap.get("state")&&!"".equals(filterMap.get("state"))){
				queryString.append(" and t1.flow_state_name like '%"+filterMap.get("state")+"%'");
			}
			if(null != filterMap.get("tianjiar")&&!"".equals(filterMap.get("tianjiar"))){
				queryString.append(" and t2.add_user_name like '%"+filterMap.get("tianjiar")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and t3.shiyankssj => '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and t3.shiyankssj <= '"+filterMap.get("endtime")+"'");
			}
		}
		
		//========================================================
		queryString.append(") ");
		queryCountString.append("select count(*) from ("+queryString+")");
		String sidx = (String) filterMap.get("sidx");
		String sord = (String) filterMap.get("sord");
		queryString.append(" order by " + sidx + " " + sord + " ");
		
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
	

	@Override
	public PageResult queryBanjie(Map<String, String> filterMap) {
		StringBuffer queryCountString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		queryString.append(" select * from ( ");
		queryString.append(" select t1.id as flowtaskinfoid,t1.flow_task_id as flowtaskid,t2.flow_type_id," +
				"t1.flow_state_id,t2.main_id,t3.renwubh,t3.chanpindh,t3.shiyanlx,t3.fuzher,t3.shiyandd,t3.shiyankssj," +
				"t3.yujijssj,t1.flow_state_name,t2.add_user_name,t2.add_time from flow_task_info t1 " +
				"left join flow_task t2 on t1.flow_task_id=t2.id " +
				"left join kl_junyans t3 on t3.id=t2.main_id "+
				"where t1.flow_state_id = 'end' and t1.state=0 " +
				"and t2.id in (select flow_task_id from flow_detailed where OPERATORPERSON_ID='"+filterMap.get("userId")+"') " );
		if (filterMap != null && !filterMap.isEmpty()) {
			
			if(null != filterMap.get("renwubh")&&!"".equals(filterMap.get("renwubh"))){
				queryString.append(" and t3.renwubh like '%"+filterMap.get("renwubh")+"%'");
			}
			if(null != filterMap.get("chanpindh")&&!"".equals(filterMap.get("chanpindh"))){
				queryString.append(" and t3.chanpindh like '%"+filterMap.get("chanpindh")+"%'");
			}
			if(null != filterMap.get("shiyanlx")&&!"".equals(filterMap.get("shiyanlx"))){
				queryString.append(" and t3.shiyanlx like '%"+filterMap.get("shiyanlx")+"%'");
			}
			if(null != filterMap.get("state")&&!"".equals(filterMap.get("state"))){
				queryString.append(" and t1.flow_state_name like '%"+filterMap.get("state")+"%'");
			}
			if(null != filterMap.get("tianjiar")&&!"".equals(filterMap.get("tianjiar"))){
				queryString.append(" and t2.add_user_name like '%"+filterMap.get("tianjiar")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and t3.shiyankssj => '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and t3.shiyankssj <= '"+filterMap.get("endtime")+"'");
			}
		}
		
		//========================================================
		queryString.append(") ");
		queryCountString.append("select count(*) from ("+queryString+")");
		String sidx = (String) filterMap.get("sidx");
		String sord = (String) filterMap.get("sord");
		queryString.append(" order by " + sidx + " " + sord + " ");
		
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}


	@Override
	public PageResult queryFlowByState(Map<String, String> filterMap) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public PageResult queryJinxing(Map<String, String> filterMap) {
		StringBuffer queryCountString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		queryString.append(" select * from ( ");
		queryString.append(" select t1.id as flowtaskinfoid,t1.flow_task_id as flowtaskid,t2.flow_type_id," +
				"t1.flow_state_id,t2.main_id,t3.renwubh,t3.chanpindh,t3.shiyanlx,t3.fuzher,t3.shiyandd,t3.shiyankssj," +
				"t3.yujijssj,t1.flow_state_name,t2.add_user_name,t2.add_time,ceil(MONTHS_BETWEEN(sysdate,t2.add_time)*30) as haoshi" +
				" from flow_task_info t1 " +
				"left join flow_task t2 on t1.flow_task_id=t2.id " +
				"left join kl_junyans t3 on t3.id=t2.main_id "+
				"where t1.flow_state_id != 'end' and t1.state=0 " );
		if (filterMap != null && !filterMap.isEmpty()) {
			
			if(null != filterMap.get("renwubh")&&!"".equals(filterMap.get("renwubh"))){
				queryString.append(" and t3.renwubh like '%"+filterMap.get("renwubh")+"%'");
			}
			if(null != filterMap.get("chanpindh")&&!"".equals(filterMap.get("chanpindh"))){
				queryString.append(" and t3.chanpindh like '%"+filterMap.get("chanpindh")+"%'");
			}
			if(null != filterMap.get("shiyanlx")&&!"".equals(filterMap.get("shiyanlx"))){
				queryString.append(" and t3.shiyanlx like '%"+filterMap.get("shiyanlx")+"%'");
			}
			if(null != filterMap.get("state")&&!"".equals(filterMap.get("state"))){
				queryString.append(" and t1.flow_state_name like '%"+filterMap.get("state")+"%'");
			}
			if(null != filterMap.get("tianjiar")&&!"".equals(filterMap.get("tianjiar"))){
				queryString.append(" and t2.add_user_name like '%"+filterMap.get("tianjiar")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and t3.shiyankssj >= '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and t3.shiyankssj <= '"+filterMap.get("endtime")+"'");
			}
		}
		
		//========================================================
		queryString.append(") ");
		queryCountString.append("select count(*) from ("+queryString+")");
		String sidx = (String) filterMap.get("sidx");
		String sord = (String) filterMap.get("sord");
		queryString.append(" order by " + sidx + " " + sord + " ");
		
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}


	@Override
	public PageResult queryCaosong(Map<String, String> filterMap) {
		StringBuffer queryCountString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		queryString.append(" select * from ( ");
		queryString.append(" select t1.id as flowtaskinfoid,t1.flow_task_id as flowtaskid,t2.flow_type_id," +
				"t1.flow_state_id,t2.main_id,t3.renwubh,t3.chanpindh,t3.shiyanlx,t3.fuzher,t3.shiyandd,t3.shiyankssj," +
				"t3.yujijssj,t1.flow_state_name,t2.add_user_name,t2.add_time from flow_task_info t1 " +
				"left join flow_task t2 on t1.flow_task_id=t2.id " +
				"left join kl_junyans t3 on t3.id=t2.main_id "+
				"where  t1.state=0 and t2.caosongrid like '%,"+filterMap.get("userId")+",%' " );
		if (filterMap != null && !filterMap.isEmpty()) {
			
			if(null != filterMap.get("renwubh")&&!"".equals(filterMap.get("renwubh"))){
				queryString.append(" and t3.renwubh like '%"+filterMap.get("renwubh")+"%'");
			}
			if(null != filterMap.get("chanpindh")&&!"".equals(filterMap.get("chanpindh"))){
				queryString.append(" and t3.chanpindh like '%"+filterMap.get("chanpindh")+"%'");
			}
			if(null != filterMap.get("shiyanlx")&&!"".equals(filterMap.get("shiyanlx"))){
				queryString.append(" and t3.shiyanlx like '%"+filterMap.get("shiyanlx")+"%'");
			}
			if(null != filterMap.get("state")&&!"".equals(filterMap.get("state"))){
				queryString.append(" and t1.flow_state_name like '%"+filterMap.get("state")+"%'");
			}
			if(null != filterMap.get("tianjiar")&&!"".equals(filterMap.get("tianjiar"))){
				queryString.append(" and t2.add_user_name like '%"+filterMap.get("tianjiar")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and t3.shiyankssj => '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and t3.shiyankssj <= '"+filterMap.get("endtime")+"'");
			}
		}
		
		//========================================================
		queryString.append(") ");
		queryCountString.append("select count(*) from ("+queryString+")");
		String sidx = (String) filterMap.get("sidx");
		String sord = (String) filterMap.get("sord");
		queryString.append(" order by " + sidx + " " + sord + " ");
		
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}


	@Override
	public PageResult queryQingqiu(Map<String, String> filterMap) {
		StringBuffer queryCountString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		queryString.append(" select * from ( ");
		queryString.append(" select t1.id as flowtaskinfoid,t1.flow_task_id as flowtaskid,t2.flow_type_id," +
				"t1.flow_state_id,t2.main_id,t3.renwubh,t3.chanpindh,t3.shiyanlx,t3.fuzher,t3.shiyandd,t3.shiyankssj," +
				"t3.yujijssj,t1.flow_state_name,t2.add_user_name,t2.add_time from flow_task_info t1 " +
				"left join flow_task t2 on t1.flow_task_id=t2.id " +
				"left join kl_junyans t3 on t3.id=t2.main_id "+
				"where  t1.state=0 and t2.add_user_id='"+filterMap.get("userId")+"' " );
		if (filterMap != null && !filterMap.isEmpty()) {
			
			if(null != filterMap.get("renwubh")&&!"".equals(filterMap.get("renwubh"))){
				queryString.append(" and t3.renwubh like '%"+filterMap.get("renwubh")+"%'");
			}
			if(null != filterMap.get("chanpindh")&&!"".equals(filterMap.get("chanpindh"))){
				queryString.append(" and t3.chanpindh like '%"+filterMap.get("chanpindh")+"%'");
			}
			if(null != filterMap.get("shiyanlx")&&!"".equals(filterMap.get("shiyanlx"))){
				queryString.append(" and t3.shiyanlx like '%"+filterMap.get("shiyanlx")+"%'");
			}
			if(null != filterMap.get("state")&&!"".equals(filterMap.get("state"))){
				queryString.append(" and t1.flow_state_name like '%"+filterMap.get("state")+"%'");
			}
			if(null != filterMap.get("tianjiar")&&!"".equals(filterMap.get("tianjiar"))){
				queryString.append(" and t2.add_user_name like '%"+filterMap.get("tianjiar")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and t3.shiyankssj => '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and t3.shiyankssj <= '"+filterMap.get("endtime")+"'");
			}
		}
		
		//========================================================
		queryString.append(") ");
		queryCountString.append("select count(*) from ("+queryString+")");
		String sidx = (String) filterMap.get("sidx");
		String sord = (String) filterMap.get("sord");
		queryString.append(" order by " + sidx + " " + sord + " ");
		
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}


	@Override
	public PageResult queryWancheng(Map<String, String> filterMap) {
		StringBuffer queryCountString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		queryString.append(" select * from ( ");
		queryString.append(" select t1.id as flowtaskinfoid,t1.flow_task_id as flowtaskid,t2.flow_type_id," +
				"t1.flow_state_id,t2.main_id,t3.renwubh,t3.chanpindh,t3.shiyanlx,t3.fuzher,t3.shiyandd,t3.shiyankssj," +
				"t3.yujijssj,t1.flow_state_name,t2.add_user_name,t2.add_time,t4.operatortime,ceil(MONTHS_BETWEEN(t4.operatortime,t2.add_time)*30) as haoshi from flow_task_info t1 " +
				"left join flow_task t2 on t1.flow_task_id=t2.id " +
				"left join kl_junyans t3 on t3.id=t2.main_id " +
				"left join flow_detailed t4 on t4.flow_task_id=t1.flow_task_id and t4.statusafterid='end' "+
				"where t1.flow_state_id = 'end' and t1.state=0 " );
		if (filterMap != null && !filterMap.isEmpty()) {
			
			if(null != filterMap.get("renwubh")&&!"".equals(filterMap.get("renwubh"))){
				queryString.append(" and t3.renwubh like '%"+filterMap.get("renwubh")+"%'");
			}
			if(null != filterMap.get("chanpindh")&&!"".equals(filterMap.get("chanpindh"))){
				queryString.append(" and t3.chanpindh like '%"+filterMap.get("chanpindh")+"%'");
			}
			if(null != filterMap.get("shiyanlx")&&!"".equals(filterMap.get("shiyanlx"))){
				queryString.append(" and t3.shiyanlx like '%"+filterMap.get("shiyanlx")+"%'");
			}
			if(null != filterMap.get("state")&&!"".equals(filterMap.get("state"))){
				queryString.append(" and t1.flow_state_name like '%"+filterMap.get("state")+"%'");
			}
			if(null != filterMap.get("tianjiar")&&!"".equals(filterMap.get("tianjiar"))){
				queryString.append(" and t2.add_user_name like '%"+filterMap.get("tianjiar")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and t3.shiyankssj >= '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and t3.shiyankssj <= '"+filterMap.get("endtime")+"'");
			}
		}
		
		//========================================================
		queryString.append(") ");
		queryCountString.append("select count(*) from ("+queryString+")");
		String sidx = (String) filterMap.get("sidx");
		String sord = (String) filterMap.get("sord");
		queryString.append(" order by " + sidx + " " + sord + " ");
		
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}

	public PageResult queryYiqigllist(Map<String, String> filterMap) {
		StringBuffer queryCountString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		queryString.append(" select * from ( ");
		queryString.append(" select t1.id as flowtaskinfoid,t1.flow_task_id as flowtaskid,t2.flow_type_id," +
				"t1.flow_state_id,t2.main_id,t3.renwubh,t3.chanpindh,t3.shiyanlx,t3.fuzher,t3.shiyandd,t3.shiyankssj," +
				"t3.yujijssj,t1.flow_state_name,t2.add_user_name,t2.add_time from flow_task_info t1 " +
				"left join flow_task t2 on t1.flow_task_id=t2.id " +
				"left join kl_junyans t3 on t3.id=t2.main_id "+
				"where  t1.state=0 and t3.id in (select junyansid from kl_junyans_yq  where yiqiid='"+filterMap.get("yiqiid")+"') " );
		if (filterMap != null && !filterMap.isEmpty()) {
			if(null != filterMap.get("renwubh")&&!"".equals(filterMap.get("renwubh"))){
				queryString.append(" and t3.renwubh like '%"+filterMap.get("renwubh")+"%'");
			}
			if(null != filterMap.get("chanpindh")&&!"".equals(filterMap.get("chanpindh"))){
				queryString.append(" and t3.chanpindh like '%"+filterMap.get("chanpindh")+"%'");
			}
			if(null != filterMap.get("shiyanlx")&&!"".equals(filterMap.get("shiyanlx"))){
				queryString.append(" and t3.shiyanlx like '%"+filterMap.get("shiyanlx")+"%'");
			}
			if(null != filterMap.get("state")&&!"".equals(filterMap.get("state"))){
				queryString.append(" and t1.flow_state_name like '%"+filterMap.get("state")+"%'");
			}
			if(null != filterMap.get("tianjiar")&&!"".equals(filterMap.get("tianjiar"))){
				queryString.append(" and t2.add_user_name like '%"+filterMap.get("tianjiar")+"%'");
			}
			if(null != filterMap.get("starttime")&&!"".equals(filterMap.get("starttime"))){
				queryString.append(" and t3.shiyankssj >= '"+filterMap.get("starttime")+"'");
			}
			if(null != filterMap.get("endtime")&&!"".equals(filterMap.get("endtime"))){
				queryString.append(" and t3.shiyankssj <= '"+filterMap.get("endtime")+"'");
			}
		}
		
		//========================================================
		queryString.append(") ");
		queryCountString.append("select count(*) from ("+queryString+")");
		String sidx = (String) filterMap.get("sidx");
		String sord = (String) filterMap.get("sord");
		queryString.append(" order by shiyankssj  " + sord + " ");
		
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}
}	
